Skip to content

Commit 3fa4b59

Browse files
committed
fix: use the system package manager instead of pip for standard modules
1 parent 678aa33 commit 3fa4b59

File tree

8 files changed

+244
-231
lines changed

8 files changed

+244
-231
lines changed

dist/actions/setup-cpp.js

Lines changed: 75 additions & 75 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: 75 additions & 75 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: 75 additions & 75 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async function setupPipx(foundPython: string) {
4747
await setupPipPackWithPython(foundPython, "pipx", undefined, { upgrade: true, usePipx: false })
4848
}
4949
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
50+
await setupPipPackWithPython(foundPython, "venv", undefined, { upgrade: false, usePipx: false })
5051
} catch (err) {
5152
warning(`Failed to install pipx: ${(err as Error).toString()}. Ignoring...`)
5253
}

src/utils/setup/setupPipPack.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ export async function setupPipPackWithPython(
5454
const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"]
5555
const userFlag = !isPipx && user ? ["--user"] : []
5656

57-
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
58-
stdio: "inherit",
59-
})
57+
const hasPackage = await pipHasPackage(givenPython, name)
58+
if (hasPackage) {
59+
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
60+
stdio: "inherit",
61+
})
62+
} else {
63+
if ((await setupPipPackSystem(name)) === null) {
64+
throw new Error(`Failed to install ${name}.`)
65+
}
66+
}
6067
} catch (err) {
6168
info(`Failed to install ${name} via ${pip}: ${err}.`)
6269
if ((await setupPipPackSystem(name)) === null) {
@@ -85,6 +92,11 @@ async function getPython_raw(): Promise<string> {
8592
}
8693
const getPython = memoize(getPython_raw)
8794

95+
async function pipHasPackage(python: string, name: string) {
96+
const result = await execa(python, ["-m", "pip", "show", name], { stdio: "ignore", reject: false })
97+
return result.exitCode === 0
98+
}
99+
88100
async function findBinDir(dirs: string[], name: string) {
89101
const exists = await Promise.all(dirs.map((dir) => pathExists(join(dir, addExeExt(name)))))
90102
const dirIndex = exists.findIndex((exist) => exist)

0 commit comments

Comments
 (0)