Skip to content

Commit 75540d0

Browse files
authored
Merge pull request #227 from aminya/python-search-windows
2 parents 7f2f3d2 + c75a134 commit 75540d0

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

dist/actions/setup-cpp.js

Lines changed: 2 additions & 2 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: 2 additions & 2 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.

src/python/python.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import assert from "assert"
2-
/* eslint-disable require-atomic-updates */
2+
import { homedir } from "os"
3+
import { parse as pathParse } from "path"
34
import { getExecOutput } from "@actions/exec"
45
import { GITHUB_ACTIONS } from "ci-info"
56
import { info, warning } from "ci-log"
67
import { execa } from "execa"
8+
import { readdir } from "fs/promises"
79
import memoize from "micro-memoize"
810
import { pathExists } from "path-exists"
911
import { addExeExt, dirname, join } from "patha"
@@ -89,7 +91,10 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string
8991
const { setupActionsPython } = await import("./actions_python")
9092
await setupActionsPython(version, setupDir, arch)
9193

92-
foundPython = (await findPython(setupDir))!
94+
foundPython = await findPython(setupDir)
95+
if (foundPython === undefined) {
96+
throw new Error("Python binary could not be found")
97+
}
9398
const binDir = dirname(foundPython)
9499
installInfo = { bin: foundPython, installDir: binDir, binDir }
95100
} catch (err) {
@@ -103,7 +108,10 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string
103108
}
104109

105110
if (foundPython === undefined || installInfo.bin === undefined) {
106-
foundPython = (await findPython(setupDir))!
111+
foundPython = await findPython(setupDir)
112+
if (foundPython === undefined) {
113+
throw new Error("Python binary could not be found")
114+
}
107115
installInfo.bin = foundPython
108116
}
109117

@@ -120,7 +128,10 @@ async function setupPythonSystem(setupDir: string, version: string) {
120128
await setupChocoPack("python3", version)
121129
}
122130
// Adding the bin dir to the path
123-
const bin = (await findPython(setupDir))!
131+
const bin = await findPython(setupDir)
132+
if (bin === undefined) {
133+
throw new Error("Python binary could not be found")
134+
}
124135
const binDir = dirname(bin)
125136
/** The directory which the tool is installed to */
126137
await addPath(binDir)
@@ -166,6 +177,24 @@ async function findPython(binDir?: string) {
166177
return foundPython
167178
}
168179
}
180+
181+
// On Windows, search in C:\PythonXX
182+
if (process.platform === "win32") {
183+
const rootDir = pathParse(homedir()).root
184+
// find all directories in rootDir using readdir
185+
const pythonDirs = (await readdir(rootDir)).filter((dir) => dir.startsWith("Python"))
186+
187+
for (const pythonDir of pythonDirs) {
188+
for (const pythonBin of ["python3", "python"]) {
189+
// eslint-disable-next-line no-await-in-loop
190+
const foundPython = await isPythonUpToDate(pythonBin, join(rootDir, pythonDir))
191+
if (foundPython !== undefined) {
192+
return foundPython
193+
}
194+
}
195+
}
196+
}
197+
169198
return undefined
170199
}
171200

0 commit comments

Comments
 (0)