Skip to content

Commit 025098a

Browse files
committed
fix: check for existence of venv module before installing
1 parent f1ec26f commit 025098a

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

dist/legacy/setup-cpp.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

+1-1
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

+1-1
Large diffs are not rendered by default.

src/llvm/__tests__/llvm.test.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,22 @@ describe("setup-llvm", () => {
6464
const directory = await setupTmpDir("llvm")
6565

6666
const osVersion = await ubuntuVersion()
67-
const { binDir } = await setupLLVM(getVersion("llvm", "true", osVersion), directory, process.arch)
68-
await testBin("clang++", ["--version"], binDir)
67+
{
68+
const { binDir } = await setupLLVM(getVersion("llvm", "true", osVersion), directory, process.arch)
69+
await testBin("clang++", ["--version"], binDir)
6970

70-
expect(process.env.CC?.includes("clang")).toBeTruthy()
71-
expect(process.env.CXX?.includes("clang++")).toBeTruthy()
71+
expect(process.env.CC?.includes("clang")).toBeTruthy()
72+
expect(process.env.CXX?.includes("clang++")).toBeTruthy()
7273

73-
// test compilation
74-
const file = join(dirname, "main.cpp")
75-
const main_exe = join(dirname, addExeExt("main"))
76-
await execa("clang++", [file, "-o", main_exe], { cwd: dirname })
77-
if (process.platform !== "win32") {
78-
await chmod(main_exe, "755")
74+
// test compilation
75+
const file = join(dirname, "main.cpp")
76+
const main_exe = join(dirname, addExeExt("main"))
77+
await execa("clang++", [file, "-o", main_exe], { cwd: dirname })
78+
if (process.platform !== "win32") {
79+
await chmod(main_exe, "755")
80+
}
81+
await execa(main_exe, { cwd: dirname, stdio: "inherit" })
7982
}
80-
await execa(main_exe, { cwd: dirname, stdio: "inherit" })
8183

8284
{
8385
const { binDir } = await setupClangFormat(getVersion("llvm", "true", osVersion), directory, process.arch)

src/python/python.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,30 @@ async function setupPipx(foundPython: string) {
6868
}
6969

7070
async function setupVenv(foundPython: string) {
71+
if (await hasVenv(foundPython)) {
72+
return
73+
}
74+
75+
info("venv module not found. Installing it...")
76+
7177
try {
72-
await setupPipPackWithPython(foundPython, "venv", undefined, { upgrade: false, usePipx: false })
78+
await setupPipPackSystem("venv")
7379
} catch (err) {
7480
info(`Failed to install venv: ${(err as Error).toString()}. Ignoring...`)
7581
}
7682
}
7783

84+
async function hasVenv(foundPython: string): Promise<boolean> {
85+
try {
86+
// check if venv module exits
87+
await execa(foundPython, ["-m", "venv", "-h"], { stdio: "inherit" })
88+
return true
89+
} catch {
90+
// if module not found, continue
91+
}
92+
return false
93+
}
94+
7895
/** Setup wheel and setuptools */
7996
async function setupWheel(foundPython: string) {
8097
try {

src/utils/setup/setupPipPack.ts

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export function setupPipPackSystem(name: string, addPythonPrefix = true) {
282282
return installAptPack([{ name: addPythonPrefix ? `python3-${name}` : name }])
283283
}
284284
} else if (process.platform === "darwin") {
285+
// brew doesn't have venv
285286
if (["venv"].includes(name)) {
286287
return null
287288
}

0 commit comments

Comments
 (0)