Skip to content

Commit

Permalink
fix: remove the pkg extension from the pip pkg names
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 18, 2024
1 parent 4ebcbc1 commit 4d73853
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions src/utils/setup/setupPipPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ export async function setupPipPackWithPython(

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) {
const installed = isPipx
? await pipxPackageInstalled(givenPython, name)
: await pipPackageIsInstalled(givenPython, name)
? await pipxPackageInstalled(givenPython, nameOnly)
: await pipPackageIsInstalled(givenPython, nameOnly)
if (installed) {
const binDir = await finishPipPackageInstall(givenPython, name)
const binDir = await finishPipPackageInstall(givenPython, nameOnly)
return { binDir }
}
}

const hasPackage = await pipHasPackage(givenPython, name)
const hasPackage = await pipHasPackage(givenPython, nameOnly)
if (hasPackage) {
try {
info(`Installing ${name} ${version ?? ""} via ${pip}`)
Expand Down Expand Up @@ -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`)
}

const binDir = await finishPipPackageInstall(givenPython, name)
const binDir = await finishPipPackageInstall(givenPython, nameOnly)
return { binDir }
}

Expand Down Expand Up @@ -171,6 +174,15 @@ async function getPython(): Promise<string> {
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) {
try {
const result = await execa(python, ["-m", "pip", "-qq", "show", name], {
Expand Down

0 comments on commit 4d73853

Please sign in to comment.