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 { unique } from "../utils/std"
|
||||||
import { MinVersions } from "../versions/default_versions"
|
import { MinVersions } from "../versions/default_versions"
|
||||||
import { pathExists } from "path-exists"
|
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> {
|
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
|
||||||
const installInfo = await findOrSetupPython(version, setupDir, arch)
|
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) {
|
async function setupPipx(foundPython: string) {
|
||||||
try {
|
try {
|
||||||
try {
|
if (!(await hasPipx())) {
|
||||||
await setupPipPackWithPython(foundPython, "pipx", undefined, true)
|
try {
|
||||||
} catch (err) {
|
await setupPipPackWithPython(foundPython, "pipx", undefined, true)
|
||||||
if (isUbuntu()) {
|
} catch (err) {
|
||||||
await setupAptPack([{ name: "python3-pipx" }])
|
if (isUbuntu()) {
|
||||||
} else if (isArch()) {
|
await setupAptPack([{ name: "python3-pipx" }])
|
||||||
await setupPacmanPack("python-pipx")
|
} else if (isArch()) {
|
||||||
} else if (hasDnf()) {
|
await setupPacmanPack("python-pipx")
|
||||||
await setupDnfPack([{ name: "python3-pipx" }])
|
} else if (hasDnf()) {
|
||||||
} else {
|
await setupDnfPack([{ name: "python3-pipx" }])
|
||||||
throw err
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
|
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
|
||||||
|
|
|
@ -22,15 +22,16 @@ export async function setupPipPackWithPython(
|
||||||
upgrade = false,
|
upgrade = false,
|
||||||
user = true,
|
user = true,
|
||||||
): Promise<InstallationInfo> {
|
): 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}`)
|
info(`Installing ${name} ${version ?? ""} via ${pip}`)
|
||||||
|
|
||||||
const nameAndVersion = version !== undefined && version !== "" ? `${name}==${version}` : name
|
const nameAndVersion = version !== undefined && version !== "" ? `${name}==${version}` : name
|
||||||
const upgradeFlag = upgrade === true ? ["--upgrade"] : []
|
const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"]
|
||||||
const userFlag = user === true ? ["--user"] : []
|
const userFlag = !isPipx && user ? ["--user"] : []
|
||||||
|
|
||||||
execaSync(givenPython, ["-m", pip, "install", ...upgradeFlag, ...userFlag, nameAndVersion], {
|
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -42,6 +43,10 @@ export async function setupPipPackWithPython(
|
||||||
return { binDir }
|
return { binDir }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function hasPipx() {
|
||||||
|
return (await which("pipx", { nothrow: true })) !== null
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
if (pythonBin === undefined) {
|
if (pythonBin === undefined) {
|
||||||
|
|
Loading…
Reference in New Issue