Skip to content

Commit 4e60284

Browse files
committed
feat: install python packages using pipx to avoid conflicts with system
1 parent 1f59ba3 commit 4e60284

File tree

9 files changed

+50
-20
lines changed

9 files changed

+50
-20
lines changed

cspell.config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ words:
3232
- DCMAKE
3333
- deps
3434
- devel
35+
- DVCPKG
3536
- dyld
3637
- eabi
3738
- esmodule
@@ -67,13 +68,15 @@ words:
6768
- OSSDK
6869
- papm
6970
- patha
71+
- pipx
7072
- pnpm
7173
- pwsh
7274
- pygments
7375
- pypy
7476
- Sccache
7577
- setupcpp
7678
- setx
79+
- SYSROOT
7780
- Syuu
7881
- terserrc
7982
- Trofimovich
@@ -83,16 +86,14 @@ words:
8386
- upleveled
8487
- vbatts
8588
- vcpkg
89+
- VCPKG
8690
- vcvarsall
8791
- visualc
8892
- visualcpp
8993
- vsversion
9094
- whatwg
9195
- xcrun
9296
- Yahyaabadi
93-
- VCPKG
94-
- DVCPKG
95-
- SYSROOT
9697
ignoreWords: []
9798
import: []
9899
dictionaryDefinitions: []

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: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,42 @@ export async function setupPython(version: string, setupDir: string, arch: strin
3434
throw new Error("pip was not installed correctly")
3535
}
3636

37-
// setup wheel and setuptools
37+
await setupPipx(foundPython)
38+
39+
await setupWheel(foundPython)
40+
41+
return installInfo
42+
}
43+
44+
async function setupPipx(foundPython: string) {
45+
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
57+
}
58+
}
59+
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
60+
} catch (err) {
61+
warning(`Failed to install pipx: ${(err as Error).toString()}. Ignoring...`)
62+
}
63+
}
64+
65+
/** Setup wheel and setuptools */
66+
async function setupWheel(foundPython: string) {
3867
try {
3968
await setupPipPackWithPython(foundPython, "setuptools", undefined, true)
4069
await setupPipPackWithPython(foundPython, "wheel", undefined, true)
4170
} catch (err) {
4271
warning(`Failed to install setuptools or wheel: ${(err as Error).toString()}. Ignoring...`)
4372
}
44-
45-
return installInfo
4673
}
4774

4875
async function findOrSetupPython(version: string, setupDir: string, arch: string) {

src/utils/setup/setupPipPack.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ export async function setupPipPackWithPython(
2222
upgrade = false,
2323
user = true,
2424
): Promise<InstallationInfo> {
25-
info(`Installing ${name} ${version ?? ""} via pip`)
25+
const pip = (await which("pipx", { nothrow: true })) !== null ? "pipx" : "pip"
26+
27+
info(`Installing ${name} ${version ?? ""} via ${pip}`)
2628

2729
const nameAndVersion = version !== undefined && version !== "" ? `${name}==${version}` : name
2830
const upgradeFlag = upgrade === true ? ["--upgrade"] : []
2931
const userFlag = user === true ? ["--user"] : []
3032

31-
execaSync(givenPython, ["-m", "pip", "install", ...upgradeFlag, ...userFlag, nameAndVersion], {
33+
execaSync(givenPython, ["-m", pip, "install", ...upgradeFlag, ...userFlag, nameAndVersion], {
3234
stdio: "inherit",
3335
})
3436

0 commit comments

Comments
 (0)