fix: remove the pkg extension from the pip pkg names

This commit is contained in:
Amin Yahyaabadi 2024-09-18 16:50:12 -07:00
parent 4ebcbc18f2
commit 4d73853d57
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
5 changed files with 21 additions and 9 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

@ -53,18 +53,21 @@ export async function setupPipPackWithPython(
const pip = isPipx ? "pipx" : "pip" const pip = isPipx ? "pipx" : "pip"
// remove `[]` extensions
const nameOnly = getPackageName(name)
// if upgrade is not requested, check if the package is already installed, and return if it is // if upgrade is not requested, check if the package is already installed, and return if it is
if (!upgrade) { if (!upgrade) {
const installed = isPipx const installed = isPipx
? await pipxPackageInstalled(givenPython, name) ? await pipxPackageInstalled(givenPython, nameOnly)
: await pipPackageIsInstalled(givenPython, name) : await pipPackageIsInstalled(givenPython, nameOnly)
if (installed) { if (installed) {
const binDir = await finishPipPackageInstall(givenPython, name) const binDir = await finishPipPackageInstall(givenPython, nameOnly)
return { binDir } return { binDir }
} }
} }
const hasPackage = await pipHasPackage(givenPython, name) const hasPackage = await pipHasPackage(givenPython, nameOnly)
if (hasPackage) { if (hasPackage) {
try { try {
info(`Installing ${name} ${version ?? ""} via ${pip}`) info(`Installing ${name} ${version ?? ""} via ${pip}`)
@ -96,7 +99,7 @@ export async function setupPipPackWithPython(
throw new Error(`Failed to install ${name} as it was not found via ${pip} or the system package manager`) throw new Error(`Failed to install ${name} as it was not found via ${pip} or the system package manager`)
} }
const binDir = await finishPipPackageInstall(givenPython, name) const binDir = await finishPipPackageInstall(givenPython, nameOnly)
return { binDir } return { binDir }
} }
@ -171,6 +174,15 @@ async function getPython(): Promise<string> {
return pythonBin return pythonBin
} }
/**
* Get the actual name of a pip package from the given string
* @param pkg the given name that might contain extensions in `[]`.
* @returns stirped down name of the package
*/
function getPackageName(pkg: string) {
return pkg.replace(/\[.*]/g, "").trim()
}
async function pipPackageIsInstalled(python: string, name: string) { async function pipPackageIsInstalled(python: string, name: string) {
try { try {
const result = await execa(python, ["-m", "pip", "-qq", "show", name], { const result = await execa(python, ["-m", "pip", "-qq", "show", name], {