Merge pull request #94 from aminya/python-test

This commit is contained in:
Amin Yahyaabadi 2022-06-29 22:36:22 -07:00 committed by GitHub
commit af7919aa41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 7 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,37 @@
import { setupPython } from "../python"
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { getVersion } from "../../default_versions"
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
import { isGitHubCI } from "../../utils/env/isci"
jest.setTimeout(300000)
describe("setup-python", () => {
let directory: string
beforeAll(async () => {
directory = await setupTmpDir("python")
})
it("should setup python in GitHub Actions", async () => {
if (isGitHubCI()) {
const installInfo = await setupPython(
getVersion("python", "true", await ubuntuVersion()),
directory,
process.arch
)
await testBin("python", ["--version"], installInfo?.binDir)
}
})
it("should setup python via system", async () => {
process.env.CI = "false"
const installInfo = await setupPython(getVersion("python", "true", await ubuntuVersion()), directory, process.arch)
await testBin("python", ["--version"], installInfo?.binDir)
})
afterAll(async () => {
await cleanupTmpDir("python")
}, 100000)
})

View File

@ -6,6 +6,9 @@ import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { isGitHubCI } from "../utils/env/isci"
import { warning, info } from "../utils/io/io"
import { isArch } from "../utils/env/isArch"
import which from "which"
import { InstallationInfo } from "../utils/setup/setupBin"
import { dirname, join } from "path"
export async function setupPython(version: string, setupDir: string, arch: string) {
if (!isGitHubCI()) {
@ -21,8 +24,12 @@ export async function setupPython(version: string, setupDir: string, arch: strin
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
export async function setupPythonViaSystem(
version: string,
setupDir: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string
): Promise<InstallationInfo> {
switch (process.platform) {
case "win32": {
if (setupDir) {
@ -30,11 +37,15 @@ export async function setupPythonViaSystem(version: string, setupDir: string, _a
} else {
await setupChocoPack("python3", version)
}
// Adding the bin dir to the path
const pythonBinPath =
which.sync("python3.exe", { nothrow: true }) ??
which.sync("python.exe", { nothrow: true }) ??
join(setupDir, "python.exe")
const pythonSetupDir = dirname(pythonBinPath)
/** The directory which the tool is installed to */
await activateWinPython(setupDir)
return { installDir: setupDir, binDir: setupDir }
await activateWinPython(pythonSetupDir)
return { installDir: pythonSetupDir, binDir: pythonSetupDir }
}
case "darwin": {
return setupBrewPack("python3", version)