fix: do not override pipx paths if env variables are specified

This commit is contained in:
Amin Yahyaabadi 2024-01-24 14:27:55 -08:00
parent 0324d60e51
commit a486582e84
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
7 changed files with 86 additions and 72 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,20 +61,9 @@ export async function setupPipPackWithPython(
const env = process.env const env = process.env
if (isPipx && user) { if (isPipx && user) {
const pipxHome = await getPipxHome()
await mkdirp(pipxHome)
await mkdirp(join(pipxHome, "trash"))
await mkdirp(join(pipxHome, "shared"))
await mkdirp(join(pipxHome, "venv"))
// install to user home // install to user home
env.PIPX_HOME = pipxHome env.PIPX_HOME = await getPipxHome()
env.PIPX_BIN_DIR = await getPipxBinDir()
const pipxBinDir = getPipxBinDir()
await addPath(pipxBinDir)
await mkdirp(pipxBinDir)
env.PIPX_BIN_DIR = pipxBinDir
} }
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], { execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
@ -106,6 +95,11 @@ export async function hasPipx(givenPython: string) {
} }
async function getPipxHome_raw() { async function getPipxHome_raw() {
let pipxHome = process.env.PIPX_HOME
if (pipxHome !== undefined) {
return pipxHome
}
// Based on https://pipx.pypa.io/stable/installation/ // Based on https://pipx.pypa.io/stable/installation/
const compatHome = untildifyUser("~/.local/pipx") const compatHome = untildifyUser("~/.local/pipx")
if (await pathExists(compatHome)) { if (await pathExists(compatHome)) {
@ -113,19 +107,39 @@ async function getPipxHome_raw() {
} }
switch (process.platform) { switch (process.platform) {
case "win32": case "win32": {
return untildifyUser("~/AppData/Local/pipx") pipxHome = untildifyUser("~/AppData/Local/pipx")
case "darwin": break
return untildifyUser("~/Library/Application Support/pipx") }
default: case "darwin": {
return untildifyUser("~/.local/share/pipx") pipxHome = untildifyUser("~/Library/Application Support/pipx")
break
}
default: {
pipxHome = untildifyUser("~/.local/share/pipx")
break
}
} }
await mkdirp(pipxHome)
await mkdirp(join(pipxHome, "trash"))
await mkdirp(join(pipxHome, "shared"))
await mkdirp(join(pipxHome, "venv"))
return pipxHome
} }
const getPipxHome = memoize(getPipxHome_raw, { isPromise: true }) const getPipxHome = memoize(getPipxHome_raw, { isPromise: true })
function getPipxBinDir() { async function getPipxBinDir_raw() {
return untildifyUser("~/.local/bin") if (process.env.PIPX_BIN_DIR !== undefined) {
return process.env.PIPX_BIN_DIR
}
const pipxBinDir = untildifyUser("~/.local/bin")
await addPath(pipxBinDir)
await mkdirp(pipxBinDir)
return pipxBinDir
} }
const getPipxBinDir = memoize(getPipxBinDir_raw, { isPromise: true })
async function getPython_raw(): Promise<string> { async function getPython_raw(): Promise<string> {
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin