Skip to content

Commit afcae25

Browse files
authored
Merge pull request #196 from aminya/venv [skip ci]
2 parents 1f91d96 + 47a297a commit afcae25

File tree

8 files changed

+262
-246
lines changed

8 files changed

+262
-246
lines changed

dist/actions/setup-cpp.js

Lines changed: 76 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/actions/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js

Lines changed: 76 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js

Lines changed: 76 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/setup/setupChocoPack.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import which from "which"
44
import { setupChocolatey } from "../../chocolatey/chocolatey"
55
import { InstallationInfo } from "./setupBin"
66
import { execaSync } from "execa"
7-
import { info } from "@actions/core"
8-
import { notice } from "ci-log"
7+
import { info } from "ci-log"
98

109
let hasChoco = false
1110

@@ -38,7 +37,7 @@ export async function setupChocoPack(name: string, version?: string, args: strin
3837
} catch (err) {
3938
// if the package requires a reboot, downgrade the error to a notice
4039
if ((err as Error).message.includes("exit code 3010")) {
41-
notice(`${name} might require a reboot for the completion of the installation.`)
40+
info(`${name} might require a reboot for the completion of the installation.`)
4241
} else {
4342
throw err
4443
}

src/utils/setup/setupPipPack.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,27 @@ export async function setupPipPackWithPython(
4747
const isPipx = usePipx && !isLibrary && (await hasPipx(givenPython))
4848
const pip = isPipx ? "pipx" : "pip"
4949

50-
info(`Installing ${name} ${version ?? ""} via ${pip}`)
51-
52-
try {
53-
const nameAndVersion = version !== undefined && version !== "" ? `${name}==${version}` : name
54-
const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"]
55-
const userFlag = !isPipx && user ? ["--user"] : []
56-
57-
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
58-
stdio: "inherit",
59-
})
60-
} catch (err) {
50+
const hasPackage = await pipHasPackage(givenPython, name)
51+
if (hasPackage) {
52+
try {
53+
info(`Installing ${name} ${version ?? ""} via ${pip}`)
54+
55+
const nameAndVersion = version !== undefined && version !== "" ? `${name}==${version}` : name
56+
const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"]
57+
const userFlag = !isPipx && user ? ["--user"] : []
58+
59+
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
60+
stdio: "inherit",
61+
})
62+
} catch (err) {
63+
info(`Failed to install ${name} via ${pip}: ${err}.`)
64+
if ((await setupPipPackSystem(name)) === null) {
65+
throw new Error(`Failed to install ${name} via ${pip}: ${err}.`)
66+
}
67+
}
68+
} else {
6169
if ((await setupPipPackSystem(name)) === null) {
62-
throw new Error(`Failed to install ${name} via ${pip} ${err}`)
70+
throw new Error(`Failed to install ${name} as it was not found via ${pip} or the system package manager`)
6371
}
6472
}
6573

@@ -84,6 +92,14 @@ async function getPython_raw(): Promise<string> {
8492
}
8593
const getPython = memoize(getPython_raw)
8694

95+
async function pipHasPackage(python: string, name: string) {
96+
const result = await execa(python, ["-m", "pip", "-qq", "index", "versions", name], {
97+
stdio: "ignore",
98+
reject: false,
99+
})
100+
return result.exitCode === 0
101+
}
102+
87103
async function findBinDir(dirs: string[], name: string) {
88104
const exists = await Promise.all(dirs.map((dir) => pathExists(join(dir, addExeExt(name)))))
89105
const dirIndex = exists.findIndex((exist) => exist)
@@ -102,6 +118,7 @@ async function findBinDir(dirs: string[], name: string) {
102118

103119
export function setupPipPackSystem(name: string) {
104120
if (process.platform === "linux") {
121+
info(`Installing ${name} via the system package manager`)
105122
if (isArch()) {
106123
return setupPacmanPack(`python-${name}`)
107124
} else if (hasDnf()) {

0 commit comments

Comments
 (0)