fix: install to the user home when using pipx as sudo

This commit is contained in:
Amin Yahyaabadi 2024-01-22 02:38:47 -08:00
parent f55ff60ae4
commit c85b694b1c
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
1 changed files with 10 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import { hasDnf } from "../env/hasDnf"
import { setupDnfPack } from "./setupDnfPack" import { setupDnfPack } from "./setupDnfPack"
import { isUbuntu } from "../env/isUbuntu" import { isUbuntu } from "../env/isUbuntu"
import { setupAptPack } from "./setupAptPack" import { setupAptPack } from "./setupAptPack"
import { untildifyUser } from "untildify-user"
export type SetupPipPackOptions = { export type SetupPipPackOptions = {
/** Whether to use pipx instead of pip */ /** Whether to use pipx instead of pip */
@ -56,8 +57,17 @@ export async function setupPipPackWithPython(
const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"] const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"]
const userFlag = !isPipx && user ? ["--user"] : [] const userFlag = !isPipx && user ? ["--user"] : []
const env = process.env
if (isPipx && user) {
// install to user home
env.PIPX_HOME = untildifyUser("~/.local/pipx")
env.PIPX_BIN_DIR = untildifyUser("~/.local/bin")
}
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], { execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
stdio: "inherit", stdio: "inherit",
env,
}) })
} catch (err) { } catch (err) {
info(`Failed to install ${name} via ${pip}: ${err}.`) info(`Failed to install ${name} via ${pip}: ${err}.`)