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 Feb 1, 2024
1 parent 8b1acb7 commit a630fde
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 53 deletions.
28 changes: 14 additions & 14 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.

6 changes: 3 additions & 3 deletions dist/legacy/actions_python.c7411d6b.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/actions_python.c7411d6b.js.map

Large diffs are not rendered by default.

28 changes: 14 additions & 14 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.

6 changes: 3 additions & 3 deletions dist/modern/actions_python.6be0dfa4.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/actions_python.6be0dfa4.js.map

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/python/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { unique } from "../utils/std"
import { MinVersions } from "../versions/default_versions"
import { pathExists } from "path-exists"
import { hasPipx, setupPipPackSystem, setupPipPackWithPython } from "../utils/setup/setupPipPack"
import { homedir } from "os"
import { parse as pathParse } from "path"
import { readdir } from "fs/promises"

export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
const installInfo = await findOrSetupPython(version, setupDir, arch)
Expand Down Expand Up @@ -166,6 +169,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 a630fde

Please sign in to comment.