feat: install pip and wheel in all cases

This commit is contained in:
Amin Yahyaabadi 2023-06-28 15:10:33 -07:00
parent 0f6b349a1e
commit 6637fda894
8 changed files with 72 additions and 71 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -15,34 +15,62 @@ import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
import { getExecOutput } from "@actions/exec"
import { isBinUptoDate } from "../utils/setup/version"
import { getVersion } from "../versions/versions"
import assert from "assert"
import { execaSync } from "execa"
import { unique } from "../utils/std"
import { DefaultVersions } from "../versions/default_versions"
export async function setupPython(version: string, setupDir: string, arch: string) {
if (!GITHUB_ACTIONS) {
// TODO parse version
return setupPythonViaSystem(version, setupDir, arch)
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
let installInfo: InstallationInfo | undefined
let foundPython = await findPython()
if (foundPython !== undefined) {
const binDir = dirname(foundPython)
installInfo = { bin: foundPython, installDir: binDir, binDir }
} else {
// if python is not found, try to install it
if (GITHUB_ACTIONS) {
// install python in GitHub Actions
try {
info("Installing python in GitHub Actions")
const { setupActionsPython } = await import("./actions_python")
await setupActionsPython(version, setupDir, arch)
foundPython = (await findPython())!
const binDir = dirname(foundPython)
installInfo = { bin: foundPython, installDir: binDir, binDir }
} catch (err) {
warning((err as Error).toString())
}
}
if (installInfo === undefined) {
// install python via system package manager
installInfo = await setupPythonSystem(setupDir, version)
}
}
if (foundPython === undefined) {
foundPython = (await findPython())!
installInfo.bin = foundPython
}
// setup pip
const foundPip = await findOrSetupPip(foundPython)
if (foundPip === undefined) {
throw new Error("pip was not installed correctly")
}
// setup wheel
try {
info("Installing python in GitHub Actions")
const { setupActionsPython } = await import("./actions_python")
return setupActionsPython(version, setupDir, arch)
setupWheel(foundPython)
} catch (err) {
warning((err as Error).toString())
return setupPythonViaSystem(version, setupDir, arch)
warning(`Failed to install wheels: ${(err as Error).toString()}. Ignoring...`)
}
return installInfo
}
export async function setupPythonViaSystem(
version: string,
setupDir: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string
): Promise<InstallationInfo> {
let installInfo: InstallationInfo
async function setupPythonSystem(setupDir: string, version: string) {
let installInfo: InstallationInfo | undefined
switch (process.platform) {
case "win32": {
if (setupDir) {
@ -81,23 +109,9 @@ export async function setupPythonViaSystem(
throw new Error("Unsupported platform")
}
}
await findOrSetupPip((await findPython())!)
return installInfo
}
/// setup python and pip if needed
export async function findOrSetupPythonAndPip(): Promise<string> {
const foundPython = await findOrSetupPython()
const foundPip = await findOrSetupPip(foundPython)
if (foundPip === undefined) {
throw new Error("pip was not installed correctly")
}
setupWheel(foundPython)
return foundPython
}
let setupPythonTried = false
async function findPython() {
if (which.sync("python3", { nothrow: true }) !== null) {
return "python3"
@ -107,23 +121,6 @@ async function findPython() {
return undefined
}
async function findOrSetupPython() {
const maybeFoundPython = await findPython()
if (maybeFoundPython !== undefined) {
return maybeFoundPython
}
if (setupPythonTried) {
throw new Error("Failed to install python")
}
setupPythonTried = true
// install python
info("python3 was not found. Installing python")
await setupPython(getVersion("python", undefined), "", process.arch)
return findOrSetupPython() // recurse
}
async function findOrSetupPip(foundPython: string) {
const maybePip = await findPip()
@ -161,12 +158,14 @@ function ensurePipUpgrade(foundPython: string) {
try {
execaSync(foundPython, ["-m", "ensurepip", "-U", "--upgrade"], { stdio: "inherit" })
return true
} catch {
} catch (err1) {
info((err1 as Error)?.toString?.())
try {
// ensure pip is disabled on Ubuntu
execaSync(foundPython, ["-m", "pip", "install", "--upgrade", "pip"], { stdio: "inherit" })
return true
} catch {
} catch (err2) {
info((err2 as Error)?.toString?.())
// pip module not found
}
}

View File

@ -34,6 +34,7 @@ export type InstallationInfo = {
/** The top install dir */
installDir?: string
binDir: string
bin?: string
}
let didInit: boolean = false

View File

@ -3,9 +3,10 @@ import { execaSync } from "execa"
import { pathExists } from "path-exists"
import { addExeExt, dirname, join } from "patha"
import which from "which"
import { addPythonBaseExecPrefix, findOrSetupPythonAndPip } from "../../python/python"
import { addPythonBaseExecPrefix, setupPython } from "../../python/python"
import { addPath } from "../env/addEnv"
import { InstallationInfo } from "./setupBin"
import { getVersion } from "../../versions/versions"
/* eslint-disable require-atomic-updates */
let python: string | undefined
@ -16,7 +17,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
info(`Installing ${name} ${version ?? ""} via pip`)
if (python === undefined) {
python = await findOrSetupPythonAndPip()
python = (await setupPython(getVersion("python", undefined), "", process.arch)).bin!
}
execaSync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {

View File

@ -28,7 +28,7 @@ export const DefaultVersions: Record<string, string | undefined> = {
task: "3.25.0", // https://github.com/go-task/task/releases
doxygen: isArch() ? "1.9.6-1" : "1.9.7", // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen // https://formulae.brew.sh/formula/doxygen // https://archlinux.org/packages/extra/x86_64/doxygen/
gcc: isArch() ? "13.1.1-1" : "13", // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
pip: "23.1.2",
pip: "22.3.1",
}
/// If an ubuntu versions is not in this map: