fix: fix library installation via pip + fix conan

This commit is contained in:
Amin Yahyaabadi 2023-09-01 03:28:05 -07:00
parent 65c4b0f5dc
commit 0916dc5cfb
9 changed files with 54 additions and 35 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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,6 @@
import { setupPipPack } from "../utils/setup/setupPipPack"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupConan(version: string | undefined, _setupDir: string, _arch: string) {
await setupPipPack("setuptools", "")
export function setupConan(version: string | undefined, _setupDir: string, _arch: string) {
return setupPipPack("conan", version)
}

View File

@ -45,7 +45,7 @@ async function setupPipx(foundPython: string) {
try {
if (!(await hasPipx(foundPython))) {
try {
await setupPipPackWithPython(foundPython, "pipx", undefined, true)
await setupPipPackWithPython(foundPython, "pipx", undefined, { upgrade: true, usePipx: false })
} catch (err) {
if (isUbuntu()) {
await setupAptPack([{ name: "python3-pipx" }])
@ -67,8 +67,12 @@ async function setupPipx(foundPython: string) {
/** Setup wheel and setuptools */
async function setupWheel(foundPython: string) {
try {
await setupPipPackWithPython(foundPython, "setuptools", undefined, true)
await setupPipPackWithPython(foundPython, "wheel", undefined, true)
await setupPipPackWithPython(foundPython, "setuptools", undefined, {
upgrade: true,
isLibrary: true,
usePipx: false,
})
await setupPipPackWithPython(foundPython, "wheel", undefined, { upgrade: true, isLibrary: true, usePipx: false })
} catch (err) {
warning(`Failed to install setuptools or wheel: ${(err as Error).toString()}. Ignoring...`)
}

View File

@ -10,19 +10,35 @@ import { getVersion } from "../../versions/versions"
import { ubuntuVersion } from "../env/ubuntu_version"
import memoize from "micro-memoize"
export type SetupPipPackOptions = {
/** Whether to use pipx instead of pip */
usePipx?: boolean
/** Whether to install the package as a user */
user?: boolean
/** Whether to upgrade the package */
upgrade?: boolean
/** Whether the package is a library */
isLibrary?: boolean
}
/** A function that installs a package using pip */
export async function setupPipPack(name: string, version?: string, upgrade = false): Promise<InstallationInfo> {
return setupPipPackWithPython(await getPython(), name, version, upgrade)
export async function setupPipPack(
name: string,
version?: string,
options: SetupPipPackOptions = {},
): Promise<InstallationInfo> {
return setupPipPackWithPython(await getPython(), name, version, options)
}
export async function setupPipPackWithPython(
givenPython: string,
name: string,
version?: string,
upgrade = false,
user = true,
options: SetupPipPackOptions = {},
): Promise<InstallationInfo> {
const isPipx = await hasPipx(givenPython)
const { usePipx = true, user = true, upgrade = false, isLibrary = false } = options
const isPipx = usePipx && !isLibrary && (await hasPipx(givenPython))
const pip = isPipx ? "pipx" : "pip"
info(`Installing ${name} ${version ?? ""} via ${pip}`)