Skip to content

Commit 6637fda

Browse files
committed
feat: install pip and wheel in all cases
1 parent 0f6b349 commit 6637fda

File tree

8 files changed

+72
-71
lines changed

8 files changed

+72
-71
lines changed

dist/node12/setup-cpp.js

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

dist/node12/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/node16/setup-cpp.js

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

dist/node16/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/python/python.ts

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,62 @@ import { setupDnfPack } from "../utils/setup/setupDnfPack"
1515
import { isUbuntu } from "../utils/env/isUbuntu"
1616
import { getExecOutput } from "@actions/exec"
1717
import { isBinUptoDate } from "../utils/setup/version"
18-
import { getVersion } from "../versions/versions"
19-
import assert from "assert"
2018
import { execaSync } from "execa"
2119
import { unique } from "../utils/std"
2220
import { DefaultVersions } from "../versions/default_versions"
2321

24-
export async function setupPython(version: string, setupDir: string, arch: string) {
25-
if (!GITHUB_ACTIONS) {
26-
// TODO parse version
27-
return setupPythonViaSystem(version, setupDir, arch)
22+
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
23+
let installInfo: InstallationInfo | undefined
24+
let foundPython = await findPython()
25+
26+
if (foundPython !== undefined) {
27+
const binDir = dirname(foundPython)
28+
installInfo = { bin: foundPython, installDir: binDir, binDir }
29+
} else {
30+
// if python is not found, try to install it
31+
if (GITHUB_ACTIONS) {
32+
// install python in GitHub Actions
33+
try {
34+
info("Installing python in GitHub Actions")
35+
const { setupActionsPython } = await import("./actions_python")
36+
await setupActionsPython(version, setupDir, arch)
37+
38+
foundPython = (await findPython())!
39+
const binDir = dirname(foundPython)
40+
installInfo = { bin: foundPython, installDir: binDir, binDir }
41+
} catch (err) {
42+
warning((err as Error).toString())
43+
}
44+
}
45+
if (installInfo === undefined) {
46+
// install python via system package manager
47+
installInfo = await setupPythonSystem(setupDir, version)
48+
}
2849
}
50+
51+
if (foundPython === undefined) {
52+
foundPython = (await findPython())!
53+
installInfo.bin = foundPython
54+
}
55+
56+
// setup pip
57+
const foundPip = await findOrSetupPip(foundPython)
58+
if (foundPip === undefined) {
59+
throw new Error("pip was not installed correctly")
60+
}
61+
62+
// setup wheel
2963
try {
30-
info("Installing python in GitHub Actions")
31-
const { setupActionsPython } = await import("./actions_python")
32-
return setupActionsPython(version, setupDir, arch)
64+
setupWheel(foundPython)
3365
} catch (err) {
34-
warning((err as Error).toString())
35-
return setupPythonViaSystem(version, setupDir, arch)
66+
warning(`Failed to install wheels: ${(err as Error).toString()}. Ignoring...`)
3667
}
68+
69+
return installInfo
3770
}
3871

39-
export async function setupPythonViaSystem(
40-
version: string,
41-
setupDir: string,
42-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
43-
_arch: string
44-
): Promise<InstallationInfo> {
45-
let installInfo: InstallationInfo
72+
async function setupPythonSystem(setupDir: string, version: string) {
73+
let installInfo: InstallationInfo | undefined
4674
switch (process.platform) {
4775
case "win32": {
4876
if (setupDir) {
@@ -81,23 +109,9 @@ export async function setupPythonViaSystem(
81109
throw new Error("Unsupported platform")
82110
}
83111
}
84-
await findOrSetupPip((await findPython())!)
85112
return installInfo
86113
}
87114

88-
/// setup python and pip if needed
89-
export async function findOrSetupPythonAndPip(): Promise<string> {
90-
const foundPython = await findOrSetupPython()
91-
const foundPip = await findOrSetupPip(foundPython)
92-
if (foundPip === undefined) {
93-
throw new Error("pip was not installed correctly")
94-
}
95-
setupWheel(foundPython)
96-
return foundPython
97-
}
98-
99-
let setupPythonTried = false
100-
101115
async function findPython() {
102116
if (which.sync("python3", { nothrow: true }) !== null) {
103117
return "python3"
@@ -107,23 +121,6 @@ async function findPython() {
107121
return undefined
108122
}
109123

110-
async function findOrSetupPython() {
111-
const maybeFoundPython = await findPython()
112-
if (maybeFoundPython !== undefined) {
113-
return maybeFoundPython
114-
}
115-
116-
if (setupPythonTried) {
117-
throw new Error("Failed to install python")
118-
}
119-
setupPythonTried = true
120-
121-
// install python
122-
info("python3 was not found. Installing python")
123-
await setupPython(getVersion("python", undefined), "", process.arch)
124-
return findOrSetupPython() // recurse
125-
}
126-
127124
async function findOrSetupPip(foundPython: string) {
128125
const maybePip = await findPip()
129126

@@ -161,12 +158,14 @@ function ensurePipUpgrade(foundPython: string) {
161158
try {
162159
execaSync(foundPython, ["-m", "ensurepip", "-U", "--upgrade"], { stdio: "inherit" })
163160
return true
164-
} catch {
161+
} catch (err1) {
162+
info((err1 as Error)?.toString?.())
165163
try {
166164
// ensure pip is disabled on Ubuntu
167165
execaSync(foundPython, ["-m", "pip", "install", "--upgrade", "pip"], { stdio: "inherit" })
168166
return true
169-
} catch {
167+
} catch (err2) {
168+
info((err2 as Error)?.toString?.())
170169
// pip module not found
171170
}
172171
}

src/utils/setup/setupBin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type InstallationInfo = {
3434
/** The top install dir */
3535
installDir?: string
3636
binDir: string
37+
bin?: string
3738
}
3839

3940
let didInit: boolean = false

src/utils/setup/setupPipPack.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { execaSync } from "execa"
33
import { pathExists } from "path-exists"
44
import { addExeExt, dirname, join } from "patha"
55
import which from "which"
6-
import { addPythonBaseExecPrefix, findOrSetupPythonAndPip } from "../../python/python"
6+
import { addPythonBaseExecPrefix, setupPython } from "../../python/python"
77
import { addPath } from "../env/addEnv"
88
import { InstallationInfo } from "./setupBin"
9+
import { getVersion } from "../../versions/versions"
910

1011
/* eslint-disable require-atomic-updates */
1112
let python: string | undefined
@@ -16,7 +17,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
1617
info(`Installing ${name} ${version ?? ""} via pip`)
1718

1819
if (python === undefined) {
19-
python = await findOrSetupPythonAndPip()
20+
python = (await setupPython(getVersion("python", undefined), "", process.arch)).bin!
2021
}
2122

2223
execaSync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {

src/versions/default_versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const DefaultVersions: Record<string, string | undefined> = {
2828
task: "3.25.0", // https://github.com/go-task/task/releases
2929
doxygen: isArch() ? "1.9.6-1" : "1.9.7", // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen // https://formulae.brew.sh/formula/doxygen // https://archlinux.org/packages/extra/x86_64/doxygen/
3030
gcc: isArch() ? "13.1.1-1" : "13", // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
31-
pip: "23.1.2",
31+
pip: "22.3.1",
3232
}
3333

3434
/// If an ubuntu versions is not in this map:

0 commit comments

Comments
 (0)