fix: fix PIPX_HOME on Windows and MacOS

This commit is contained in:
Amin Yahyaabadi 2024-01-22 21:02:38 -08:00
parent 1a3ed1a856
commit f3a5dc3f05
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
7 changed files with 75 additions and 53 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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -61,8 +61,8 @@ export async function setupPipPackWithPython(
if (isPipx && user) {
// install to user home
env.PIPX_HOME = untildifyUser("~/.local/pipx")
env.PIPX_BIN_DIR = untildifyUser("~/.local/bin")
env.PIPX_HOME = await getPipxHome()
env.PIPX_BIN_DIR = getPipxBinDir()
}
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
@ -93,6 +93,28 @@ export async function hasPipx(givenPython: string) {
return (await execa(givenPython, ["-m", "pipx", "--help"], { stdio: "ignore", reject: false })).exitCode === 0
}
async function getPipxHome_raw() {
// Based on https://pipx.pypa.io/stable/installation/
const compatHome = untildifyUser("~/.local/pipx")
if (await pathExists(compatHome)) {
return compatHome
}
switch (process.platform) {
case "win32":
return untildifyUser("~/AppData/Local/pipx")
case "darwin":
return untildifyUser("~/Library/Application Support/pipx")
default:
return untildifyUser("~/.local/share/pipx")
}
}
const getPipxHome = memoize(getPipxHome_raw, { isPromise: true })
function getPipxBinDir() {
return untildifyUser("~/.local/bin")
}
async function getPython_raw(): Promise<string> {
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
if (pythonBin === undefined) {