Skip to content

Commit

Permalink
fix: fix pipx ensure path failures
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 12, 2025
1 parent 361073a commit 627f57a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions src/python/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import type { InstallationInfo } from "../utils/setup/setupBin.js"
import { setupChocoPack } from "../utils/setup/setupChocoPack.js"
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
import { hasPipx, setupPipPackSystem, setupPipPackWithPython } from "../utils/setup/setupPipPack.js"
import {
hasPipxBinary,
hasPipxModule,
setupPipPackSystem,
setupPipPackWithPython,
} from "../utils/setup/setupPipPack.js"
import { isBinUptoDate } from "../utils/setup/version.js"
import { unique } from "../utils/std/index.js"
import { getVersionDefault, isMinVersion } from "../versions/versions.js"
Expand Down Expand Up @@ -53,7 +58,7 @@ export async function setupPython(

async function setupPipx(foundPython: string) {
try {
if (!(await hasPipx(foundPython))) {
if (!(await hasPipxModule(foundPython))) {
try {
// first try with the system-wide pipx
if ((await setupPipPackSystem("pipx", isArch())) === null) {
Expand All @@ -64,7 +69,15 @@ async function setupPipx(foundPython: string) {
throw new Error(`pipx was not installed correctly ${err}`)
}
}
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
if (await hasPipxModule(foundPython)) {
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
return
} else if (await hasPipxBinary()) {
await execa("pipx", ["ensurepath"], { stdio: "inherit" })
return
} else {
notice("pipx module or pipx binary not found. Corrput pipx installation.")
}
} catch (err) {
notice(`Failed to install pipx: ${(err as Error).toString()}. Ignoring...`)
}
Expand Down
8 changes: 6 additions & 2 deletions src/utils/setup/setupPipPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function setupPipPackWithPython(
): Promise<InstallationInfo> {
const { usePipx = true, user = true, upgrade = false, isLibrary = false } = options

const isPipx = usePipx && !isLibrary && (await hasPipx(givenPython))
const isPipx = usePipx && !isLibrary && (await hasPipxModule(givenPython))

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

Expand Down Expand Up @@ -120,7 +120,11 @@ async function finishPipPackageInstall(givenPython: string, name: string) {
return binDir
}

export async function hasPipx(givenPython: string) {
export async function hasPipxBinary() {
return (await which("pipx", { nothrow: true })) !== null
}

export async function hasPipxModule(givenPython: string) {
const res = await execa(givenPython, ["-m", "pipx", "--help"], { stdio: "ignore", reject: false })
return res.exitCode === 0
}
Expand Down

0 comments on commit 627f57a

Please sign in to comment.