Skip to content

Commit

Permalink
fix: use choco to install python on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Feb 4, 2022
1 parent f21f0db commit dd678f2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@actions/io": "^1.1.1",
"@actions/tool-cache": "^1.7.1",
"execa": "^5.1.1",
"hasha": "^5.2.2",
"mri": "^1.2.0",
"msvc-dev-cmd": "git://github.com/aminya/msvc-dev-cmd#9f672c1",
"semver": "^7.3.5",
Expand Down
23 changes: 11 additions & 12 deletions src/python/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { addPath } from "../utils/path/addPath"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack"
import hasha from "hasha"
import { join } from "path"
import { isGitHubCI } from "../utils/env/isci"

export function setupPython(version: string, setupDir: string, arch: string) {
Expand All @@ -13,6 +11,12 @@ export function setupPython(version: string, setupDir: string, arch: string) {
return setupPythonViaSystem("", setupDir, arch)
}
try {
if (process.platform === "win32") {
// Windows has issues with setup-python
// See this: https://github.com/aminya/setup-cpp/issues/27
return setupPythonViaSystem(version, setupDir, arch)
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { setupActionsPython } = require("./actions_python") as typeof import("./actions_python")
return setupActionsPython(version, setupDir, arch)
Expand All @@ -21,20 +25,15 @@ export function setupPython(version: string, setupDir: string, arch: string) {
}
}

export async function setupPythonViaSystem(version: string, setupDir: string, arch: string) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
switch (process.platform) {
case "win32": {
// Get an unique output directory name from the URL.
const key: string = await hasha.async(version + arch, { algorithm: "md5" })
const installDir = join(setupDir, key, "python")
const binDir = installDir
await setupChocoPack("python3", version, [`/InstallDir:${installDir}`])

await setupChocoPack("python3", version, [`/InstallDir:${setupDir}`])
// Adding the bin dir to the path
/** The directory which the tool is installed to */
activateWinPython(binDir)

return { installDir, binDir }
activateWinPython(setupDir)
return { installDir: setupDir, binDir: setupDir }
}
case "darwin": {
return setupBrewPack("python3", version)
Expand Down

0 comments on commit dd678f2

Please sign in to comment.