Skip to content

Commit 627f57a

Browse files
committed
fix: fix pipx ensure path failures
1 parent 361073a commit 627f57a

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/python/python.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import type { InstallationInfo } from "../utils/setup/setupBin.js"
2222
import { setupChocoPack } from "../utils/setup/setupChocoPack.js"
2323
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
2424
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
25-
import { hasPipx, setupPipPackSystem, setupPipPackWithPython } from "../utils/setup/setupPipPack.js"
25+
import {
26+
hasPipxBinary,
27+
hasPipxModule,
28+
setupPipPackSystem,
29+
setupPipPackWithPython,
30+
} from "../utils/setup/setupPipPack.js"
2631
import { isBinUptoDate } from "../utils/setup/version.js"
2732
import { unique } from "../utils/std/index.js"
2833
import { getVersionDefault, isMinVersion } from "../versions/versions.js"
@@ -53,7 +58,7 @@ export async function setupPython(
5358

5459
async function setupPipx(foundPython: string) {
5560
try {
56-
if (!(await hasPipx(foundPython))) {
61+
if (!(await hasPipxModule(foundPython))) {
5762
try {
5863
// first try with the system-wide pipx
5964
if ((await setupPipPackSystem("pipx", isArch())) === null) {
@@ -64,7 +69,15 @@ async function setupPipx(foundPython: string) {
6469
throw new Error(`pipx was not installed correctly ${err}`)
6570
}
6671
}
67-
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
72+
if (await hasPipxModule(foundPython)) {
73+
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
74+
return
75+
} else if (await hasPipxBinary()) {
76+
await execa("pipx", ["ensurepath"], { stdio: "inherit" })
77+
return
78+
} else {
79+
notice("pipx module or pipx binary not found. Corrput pipx installation.")
80+
}
6881
} catch (err) {
6982
notice(`Failed to install pipx: ${(err as Error).toString()}. Ignoring...`)
7083
}

src/utils/setup/setupPipPack.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function setupPipPackWithPython(
5151
): Promise<InstallationInfo> {
5252
const { usePipx = true, user = true, upgrade = false, isLibrary = false } = options
5353

54-
const isPipx = usePipx && !isLibrary && (await hasPipx(givenPython))
54+
const isPipx = usePipx && !isLibrary && (await hasPipxModule(givenPython))
5555

5656
const pip = isPipx ? "pipx" : "pip"
5757

@@ -120,7 +120,11 @@ async function finishPipPackageInstall(givenPython: string, name: string) {
120120
return binDir
121121
}
122122

123-
export async function hasPipx(givenPython: string) {
123+
export async function hasPipxBinary() {
124+
return (await which("pipx", { nothrow: true })) !== null
125+
}
126+
127+
export async function hasPipxModule(givenPython: string) {
124128
const res = await execa(givenPython, ["-m", "pipx", "--help"], { stdio: "ignore", reject: false })
125129
return res.exitCode === 0
126130
}

0 commit comments

Comments
 (0)