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,6 +43,7 @@ export async function setupPython(version: string, setupDir: string, arch: strin
|
||||||
|
|
||||||
async function setupPipx(foundPython: string) {
|
async function setupPipx(foundPython: string) {
|
||||||
try {
|
try {
|
||||||
|
if (!(await hasPipx())) {
|
||||||
try {
|
try {
|
||||||
await setupPipPackWithPython(foundPython, "pipx", undefined, true)
|
await setupPipPackWithPython(foundPython, "pipx", undefined, true)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -56,6 +57,7 @@ async function setupPipx(foundPython: string) {
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
|
await execa(foundPython, ["-m", "pipx", "ensurepath"], { stdio: "inherit" })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
warning(`Failed to install pipx: ${(err as Error).toString()}. Ignoring...`)
|
warning(`Failed to install pipx: ${(err as Error).toString()}. Ignoring...`)
|
||||||
|
|
|
@ -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