fix: check for existence of venv module before installing

This commit is contained in:
Amin Yahyaabadi 2025-01-12 02:32:41 -08:00
parent f1ec26fa74
commit 025098a948
7 changed files with 36 additions and 16 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -64,20 +64,22 @@ describe("setup-llvm", () => {
const directory = await setupTmpDir("llvm")
const osVersion = await ubuntuVersion()
const { binDir } = await setupLLVM(getVersion("llvm", "true", osVersion), directory, process.arch)
await testBin("clang++", ["--version"], binDir)
{
const { binDir } = await setupLLVM(getVersion("llvm", "true", osVersion), directory, process.arch)
await testBin("clang++", ["--version"], binDir)
expect(process.env.CC?.includes("clang")).toBeTruthy()
expect(process.env.CXX?.includes("clang++")).toBeTruthy()
expect(process.env.CC?.includes("clang")).toBeTruthy()
expect(process.env.CXX?.includes("clang++")).toBeTruthy()
// test compilation
const file = join(dirname, "main.cpp")
const main_exe = join(dirname, addExeExt("main"))
await execa("clang++", [file, "-o", main_exe], { cwd: dirname })
if (process.platform !== "win32") {
await chmod(main_exe, "755")
// test compilation
const file = join(dirname, "main.cpp")
const main_exe = join(dirname, addExeExt("main"))
await execa("clang++", [file, "-o", main_exe], { cwd: dirname })
if (process.platform !== "win32") {
await chmod(main_exe, "755")
}
await execa(main_exe, { cwd: dirname, stdio: "inherit" })
}
await execa(main_exe, { cwd: dirname, stdio: "inherit" })
{
const { binDir } = await setupClangFormat(getVersion("llvm", "true", osVersion), directory, process.arch)

View File

@ -68,13 +68,30 @@ async function setupPipx(foundPython: string) {
}
async function setupVenv(foundPython: string) {
if (await hasVenv(foundPython)) {
return
}
info("venv module not found. Installing it...")
try {
await setupPipPackWithPython(foundPython, "venv", undefined, { upgrade: false, usePipx: false })
await setupPipPackSystem("venv")
} catch (err) {
info(`Failed to install venv: ${(err as Error).toString()}. Ignoring...`)
}
}
async function hasVenv(foundPython: string): Promise<boolean> {
try {
// check if venv module exits
await execa(foundPython, ["-m", "venv", "-h"], { stdio: "inherit" })
return true
} catch {
// if module not found, continue
}
return false
}
/** Setup wheel and setuptools */
async function setupWheel(foundPython: string) {
try {

View File

@ -282,6 +282,7 @@ export function setupPipPackSystem(name: string, addPythonPrefix = true) {
return installAptPack([{ name: addPythonPrefix ? `python3-${name}` : name }])
}
} else if (process.platform === "darwin") {
// brew doesn't have venv
if (["venv"].includes(name)) {
return null
}