Skip to content

Commit 09fad1b

Browse files
committed
feat: use the setupDir in findPython
1 parent f6ebfc1 commit 09fad1b

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

dist/node12/setup-cpp.js

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/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: 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.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: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { GITHUB_ACTIONS } from "ci-info"
55
import { info, warning } from "ci-log"
66
import { execaSync } from "execa"
77
import memoize from "micro-memoize"
8-
import { dirname, join } from "patha"
8+
import { addExeExt, dirname, join } from "patha"
99
import which from "which"
1010
import { addPath } from "../utils/env/addEnv"
1111
import { hasDnf } from "../utils/env/hasDnf"
@@ -20,6 +20,7 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
2020
import { isBinUptoDate } from "../utils/setup/version"
2121
import { unique } from "../utils/std"
2222
import { DefaultVersions } from "../versions/default_versions"
23+
import { pathExists } from "path-exists"
2324

2425
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
2526
const installInfo = await findOrSetupPython(version, setupDir, arch)
@@ -47,7 +48,7 @@ export async function setupPython(version: string, setupDir: string, arch: strin
4748

4849
async function findOrSetupPython(version: string, setupDir: string, arch: string) {
4950
let installInfo: InstallationInfo | undefined
50-
let foundPython = await findPython()
51+
let foundPython = await findPython(setupDir)
5152

5253
if (foundPython !== undefined) {
5354
const binDir = dirname(foundPython)
@@ -61,7 +62,7 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string
6162
const { setupActionsPython } = await import("./actions_python")
6263
await setupActionsPython(version, setupDir, arch)
6364

64-
foundPython = (await findPython())!
65+
foundPython = (await findPython(setupDir))!
6566
const binDir = dirname(foundPython)
6667
installInfo = { bin: foundPython, installDir: binDir, binDir }
6768
} catch (err) {
@@ -74,8 +75,8 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string
7475
}
7576
}
7677

77-
if (foundPython === undefined) {
78-
foundPython = (await findPython())!
78+
if (foundPython === undefined || installInfo.bin === undefined) {
79+
foundPython = (await findPython(setupDir))!
7980
installInfo.bin = foundPython
8081
}
8182

@@ -92,14 +93,11 @@ async function setupPythonSystem(setupDir: string, version: string) {
9293
await setupChocoPack("python3", version)
9394
}
9495
// Adding the bin dir to the path
95-
const pythonBinPath =
96-
which.sync("python3.exe", { nothrow: true }) ??
97-
which.sync("python.exe", { nothrow: true }) ??
98-
join(setupDir, "python.exe")
99-
const pythonSetupDir = dirname(pythonBinPath)
96+
const bin = (await findPython(setupDir))!
97+
const binDir = dirname(bin)
10098
/** The directory which the tool is installed to */
101-
await addPath(pythonSetupDir)
102-
installInfo = { installDir: pythonSetupDir, binDir: pythonSetupDir }
99+
await addPath(binDir)
100+
installInfo = { installDir: binDir, binDir, bin }
103101
break
104102
}
105103
case "darwin": {
@@ -125,7 +123,15 @@ async function setupPythonSystem(setupDir: string, version: string) {
125123
return installInfo
126124
}
127125

128-
async function findPython() {
126+
async function findPython(binDir?: string) {
127+
if (binDir !== undefined) {
128+
for (const pythonBinPath of ["python3", "python"]) {
129+
// eslint-disable-next-line no-await-in-loop
130+
if (await pathExists(join(binDir, addExeExt(pythonBinPath)))) {
131+
return pythonBinPath
132+
}
133+
}
134+
}
129135
if (which.sync("python3", { nothrow: true }) !== null) {
130136
return "python3"
131137
} else if (which.sync("python", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) {

0 commit comments

Comments
 (0)