Skip to content

Commit 512202e

Browse files
committed
fix: handle upgrade/user flags for pipx
1 parent 4e60284 commit 512202e

File tree

8 files changed

+35
-28
lines changed

8 files changed

+35
-28
lines changed

dist/actions/setup-cpp.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/actions/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/legacy/setup-cpp.js

Lines changed: 3 additions & 3 deletions
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.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/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.

src/python/python.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { isBinUptoDate } from "../utils/setup/version"
2121
import { unique } from "../utils/std"
2222
import { MinVersions } from "../versions/default_versions"
2323
import { pathExists } from "path-exists"
24-
import { setupPipPackWithPython } from "../utils/setup/setupPipPack"
24+
import { hasPipx, setupPipPackWithPython } from "../utils/setup/setupPipPack"
2525

2626
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
2727
const installInfo = await findOrSetupPython(version, setupDir, arch)
@@ -43,17 +43,19 @@ export async function setupPython(version: string, setupDir: string, arch: strin
4343

4444
async function setupPipx(foundPython: string) {
4545
try {
46-
try {
47-
await setupPipPackWithPython(foundPython, "pipx", undefined, true)
48-
} catch (err) {
49-
if (isUbuntu()) {
50-
await setupAptPack([{ name: "python3-pipx" }])
51-
} else if (isArch()) {
52-
await setupPacmanPack("python-pipx")
53-
} else if (hasDnf()) {
54-
await setupDnfPack([{ name: "python3-pipx" }])
55-
} else {
56-
throw err
46+
if (!(await hasPipx())) {
47+
try {
48+
await setupPipPackWithPython(foundPython, "pipx", undefined, true)
49+
} catch (err) {
50+
if (isUbuntu()) {
51+
await setupAptPack([{ name: "python3-pipx" }])
52+
} else if (isArch()) {
53+
await setupPacmanPack("python-pipx")
54+
} else if (hasDnf()) {
55+
await setupDnfPack([{ name: "python3-pipx" }])
56+
} else {
57+
throw err
58+
}
5759
}
5860
}
5961
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })

src/utils/setup/setupPipPack.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ export async function setupPipPackWithPython(
2222
upgrade = false,
2323
user = true,
2424
): Promise<InstallationInfo> {
25-
const pip = (await which("pipx", { nothrow: true })) !== null ? "pipx" : "pip"
25+
const isPipx = await hasPipx()
26+
const pip = isPipx ? "pipx" : "pip"
2627

2728
info(`Installing ${name} ${version ?? ""} via ${pip}`)
2829

2930
const nameAndVersion = version !== undefined && version !== "" ? `${name}==${version}` : name
30-
const upgradeFlag = upgrade === true ? ["--upgrade"] : []
31-
const userFlag = user === true ? ["--user"] : []
31+
const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"]
32+
const userFlag = !isPipx && user ? ["--user"] : []
3233

33-
execaSync(givenPython, ["-m", pip, "install", ...upgradeFlag, ...userFlag, nameAndVersion], {
34+
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
3435
stdio: "inherit",
3536
})
3637

@@ -42,6 +43,10 @@ export async function setupPipPackWithPython(
4243
return { binDir }
4344
}
4445

46+
export async function hasPipx() {
47+
return (await which("pipx", { nothrow: true })) !== null
48+
}
49+
4550
async function getPython_raw(): Promise<string> {
4651
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
4752
if (pythonBin === undefined) {

0 commit comments

Comments
 (0)