Skip to content

Commit

Permalink
fix: do not override pipx paths if env variables are specified
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 24, 2024
1 parent 0324d60 commit a486582
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 72 deletions.
32 changes: 16 additions & 16 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

56 changes: 35 additions & 21 deletions src/utils/setup/setupPipPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,9 @@ export async function setupPipPackWithPython(
const env = process.env

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
env.PIPX_HOME = pipxHome

const pipxBinDir = getPipxBinDir()
await addPath(pipxBinDir)
await mkdirp(pipxBinDir)

env.PIPX_BIN_DIR = pipxBinDir
env.PIPX_HOME = await getPipxHome()
env.PIPX_BIN_DIR = await getPipxBinDir()
}

execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
Expand Down Expand Up @@ -106,26 +95,51 @@ export async function hasPipx(givenPython: string) {
}

async function getPipxHome_raw() {
let pipxHome = process.env.PIPX_HOME
if (pipxHome !== undefined) {
return pipxHome
}

// 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")
case "win32": {
pipxHome = untildifyUser("~/AppData/Local/pipx")
break
}
case "darwin": {
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 })

function getPipxBinDir() {
return untildifyUser("~/.local/bin")
async function getPipxBinDir_raw() {
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> {
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
Expand Down

0 comments on commit a486582

Please sign in to comment.