Skip to content

Commit af7919a

Browse files
authored
Merge pull request #94 from aminya/python-test
2 parents a4796aa + 1e2c406 commit af7919a

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-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/__tests__/python.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { setupPython } from "../python"
2+
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
3+
import { getVersion } from "../../default_versions"
4+
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
5+
import { isGitHubCI } from "../../utils/env/isci"
6+
7+
jest.setTimeout(300000)
8+
describe("setup-python", () => {
9+
let directory: string
10+
beforeAll(async () => {
11+
directory = await setupTmpDir("python")
12+
})
13+
14+
it("should setup python in GitHub Actions", async () => {
15+
if (isGitHubCI()) {
16+
const installInfo = await setupPython(
17+
getVersion("python", "true", await ubuntuVersion()),
18+
directory,
19+
process.arch
20+
)
21+
22+
await testBin("python", ["--version"], installInfo?.binDir)
23+
}
24+
})
25+
26+
it("should setup python via system", async () => {
27+
process.env.CI = "false"
28+
29+
const installInfo = await setupPython(getVersion("python", "true", await ubuntuVersion()), directory, process.arch)
30+
31+
await testBin("python", ["--version"], installInfo?.binDir)
32+
})
33+
34+
afterAll(async () => {
35+
await cleanupTmpDir("python")
36+
}, 100000)
37+
})

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)