Skip to content

Commit

Permalink
fix: add default search paths for python on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Aug 7, 2024
1 parent 45a40e9 commit c75a134
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion src/python/python.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import assert from "assert"
/* eslint-disable require-atomic-updates */
import { homedir } from "os"
import { parse as pathParse } from "path"
import { getExecOutput } from "@actions/exec"
import { GITHUB_ACTIONS } from "ci-info"
import { info, warning } from "ci-log"
import { execa } from "execa"
import { readdir } from "fs/promises"
import memoize from "micro-memoize"
import { pathExists } from "path-exists"
import { addExeExt, dirname, join } from "patha"
Expand Down Expand Up @@ -175,6 +177,24 @@ async function findPython(binDir?: string) {
return foundPython
}
}

// On Windows, search in C:\PythonXX
if (process.platform === "win32") {
const rootDir = pathParse(homedir()).root
// find all directories in rootDir using readdir
const pythonDirs = (await readdir(rootDir)).filter((dir) => dir.startsWith("Python"))

for (const pythonDir of pythonDirs) {
for (const pythonBin of ["python3", "python"]) {
// eslint-disable-next-line no-await-in-loop
const foundPython = await isPythonUpToDate(pythonBin, join(rootDir, pythonDir))
if (foundPython !== undefined) {
return foundPython
}
}
}
}

return undefined
}

Expand Down

0 comments on commit c75a134

Please sign in to comment.