mirror of https://github.com/aminya/setup-cpp
fix: handle upgrade/user flags for pipx
This commit is contained in:
parent
4e60284097
commit
512202e7f4
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
|
@ -21,7 +21,7 @@ import { isBinUptoDate } from "../utils/setup/version"
|
|||
import { unique } from "../utils/std"
|
||||
import { MinVersions } from "../versions/default_versions"
|
||||
import { pathExists } from "path-exists"
|
||||
import { setupPipPackWithPython } from "../utils/setup/setupPipPack"
|
||||
import { hasPipx, setupPipPackWithPython } from "../utils/setup/setupPipPack"
|
||||
|
||||
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
|
||||
const installInfo = await findOrSetupPython(version, setupDir, arch)
|
||||
|
@ -43,17 +43,19 @@ export async function setupPython(version: string, setupDir: string, arch: strin
|
|||
|
||||
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
|
||||
if (!(await hasPipx())) {
|
||||
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" })
|
||||
|
|
|
@ -22,15 +22,16 @@ export async function setupPipPackWithPython(
|
|||
upgrade = false,
|
||||
user = true,
|
||||
): Promise<InstallationInfo> {
|
||||
const pip = (await which("pipx", { nothrow: true })) !== null ? "pipx" : "pip"
|
||||
const isPipx = await hasPipx()
|
||||
const pip = isPipx ? "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"] : []
|
||||
const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"]
|
||||
const userFlag = !isPipx && user ? ["--user"] : []
|
||||
|
||||
execaSync(givenPython, ["-m", pip, "install", ...upgradeFlag, ...userFlag, nameAndVersion], {
|
||||
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
|
||||
stdio: "inherit",
|
||||
})
|
||||
|
||||
|
@ -42,6 +43,10 @@ export async function setupPipPackWithPython(
|
|||
return { binDir }
|
||||
}
|
||||
|
||||
export async function hasPipx() {
|
||||
return (await which("pipx", { nothrow: true })) !== null
|
||||
}
|
||||
|
||||
async function getPython_raw(): Promise<string> {
|
||||
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
|
||||
if (pythonBin === undefined) {
|
||||
|
|
Loading…
Reference in New Issue