feat: install python packages using pipx to avoid conflicts with system

This commit is contained in:
Amin Yahyaabadi 2023-09-01 02:49:28 -07:00
parent 1f59ba33f1
commit 4e60284097
9 changed files with 50 additions and 20 deletions

View File

@ -32,6 +32,7 @@ words:
- DCMAKE
- deps
- devel
- DVCPKG
- dyld
- eabi
- esmodule
@ -67,6 +68,7 @@ words:
- OSSDK
- papm
- patha
- pipx
- pnpm
- pwsh
- pygments
@ -74,6 +76,7 @@ words:
- Sccache
- setupcpp
- setx
- SYSROOT
- Syuu
- terserrc
- Trofimovich
@ -83,6 +86,7 @@ words:
- upleveled
- vbatts
- vcpkg
- VCPKG
- vcvarsall
- visualc
- visualcpp
@ -90,9 +94,6 @@ words:
- whatwg
- xcrun
- Yahyaabadi
- VCPKG
- DVCPKG
- SYSROOT
ignoreWords: []
import: []
dictionaryDefinitions: []

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -34,15 +34,42 @@ export async function setupPython(version: string, setupDir: string, arch: strin
throw new Error("pip was not installed correctly")
}
// setup wheel and setuptools
await setupPipx(foundPython)
await setupWheel(foundPython)
return installInfo
}
async function setupPipx(foundPython: string) {
try {
try {
await setupPipPackWithPython(foundPython, "pipx", undefined, true)
} catch (err) {
if (isUbuntu()) {
await setupAptPack([{ name: "python3-pipx" }])
} else if (isArch()) {
await setupPacmanPack("python-pipx")
} else if (hasDnf()) {
await setupDnfPack([{ name: "python3-pipx" }])
} else {
throw err
}
}
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
} catch (err) {
warning(`Failed to install pipx: ${(err as Error).toString()}. Ignoring...`)
}
}
/** Setup wheel and setuptools */
async function setupWheel(foundPython: string) {
try {
await setupPipPackWithPython(foundPython, "setuptools", undefined, true)
await setupPipPackWithPython(foundPython, "wheel", undefined, true)
} catch (err) {
warning(`Failed to install setuptools or wheel: ${(err as Error).toString()}. Ignoring...`)
}
return installInfo
}
async function findOrSetupPython(version: string, setupDir: string, arch: string) {

View File

@ -22,13 +22,15 @@ export async function setupPipPackWithPython(
upgrade = false,
user = true,
): Promise<InstallationInfo> {
info(`Installing ${name} ${version ?? ""} via pip`)
const pip = (await which("pipx", { nothrow: true })) !== null ? "pipx" : "pip"
info(`Installing ${name} ${version ?? ""} via ${pip}`)
const nameAndVersion = version !== undefined && version !== "" ? `${name}==${version}` : name
const upgradeFlag = upgrade === true ? ["--upgrade"] : []
const userFlag = user === true ? ["--user"] : []
execaSync(givenPython, ["-m", "pip", "install", ...upgradeFlag, ...userFlag, nameAndVersion], {
execaSync(givenPython, ["-m", pip, "install", ...upgradeFlag, ...userFlag, nameAndVersion], {
stdio: "inherit",
})