Skip to content

Commit 1e2c406

Browse files
committed
fix: find the path of python on windows using which
1 parent 043050f commit 1e2c406

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

dist/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/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: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { setupChocoPack } from "../utils/setup/setupChocoPack"
66
import { isGitHubCI } from "../utils/env/isci"
77
import { warning, info } from "../utils/io/io"
88
import { isArch } from "../utils/env/isArch"
9+
import which from "which"
10+
import { InstallationInfo } from "../utils/setup/setupBin"
11+
import { dirname, join } from "path"
912

1013
export async function setupPython(version: string, setupDir: string, arch: string) {
1114
if (!isGitHubCI()) {
@@ -21,20 +24,28 @@ export async function setupPython(version: string, setupDir: string, arch: strin
2124
}
2225
}
2326

24-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
25-
export async function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
27+
export async function setupPythonViaSystem(
28+
version: string,
29+
setupDir: string,
30+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31+
_arch: string
32+
): Promise<InstallationInfo> {
2633
switch (process.platform) {
2734
case "win32": {
2835
if (setupDir) {
2936
await setupChocoPack("python3", version, [`--params=/InstallDir:${setupDir}`])
3037
} else {
3138
await setupChocoPack("python3", version)
3239
}
33-
3440
// Adding the bin dir to the path
41+
const pythonBinPath =
42+
which.sync("python3.exe", { nothrow: true }) ??
43+
which.sync("python.exe", { nothrow: true }) ??
44+
join(setupDir, "python.exe")
45+
const pythonSetupDir = dirname(pythonBinPath)
3546
/** The directory which the tool is installed to */
36-
await activateWinPython(setupDir)
37-
return { installDir: setupDir, binDir: setupDir }
47+
await activateWinPython(pythonSetupDir)
48+
return { installDir: pythonSetupDir, binDir: pythonSetupDir }
3849
}
3950
case "darwin": {
4051
return setupBrewPack("python3", version)

0 commit comments

Comments
 (0)