fix: check all the python/pip binaries on the PATH

This commit is contained in:
Amin Yahyaabadi 2023-06-29 13:58:48 -07:00
parent d841abd854
commit b5439543fd
5 changed files with 30 additions and 26 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

@ -121,15 +121,14 @@ async function setupPythonSystem(setupDir: string, version: string) {
} }
async function findPython(binDir?: string) { async function findPython(binDir?: string) {
const foundBins = ( for (const pythonBin of ["python3", "python"]) {
await Promise.all(["python3", "python"].map((pythonBin) => isPythonUpToDate(pythonBin, binDir))) // eslint-disable-next-line no-await-in-loop
).filter((bin) => bin !== undefined) as string[] const foundPython = await isPythonUpToDate(pythonBin, binDir)
if (foundPython !== undefined) {
if (foundBins.length === 0) { return foundPython
return undefined }
} }
return undefined
return foundBins[0]
} }
async function isPythonUpToDate(candidate: string, binDir?: string) { async function isPythonUpToDate(candidate: string, binDir?: string) {
@ -142,9 +141,12 @@ async function isPythonUpToDate(candidate: string, binDir?: string) {
} }
} }
} }
const pythonBinPath: string | null = await which(candidate, { nothrow: true }) const pythonBinPaths = (await which(candidate, { nothrow: true, all: true })) ?? []
if (pythonBinPath !== null && (await isBinUptoDate(pythonBinPath, MinVersions.python!))) { for (const pythonBinPath of pythonBinPaths) {
return pythonBinPath // eslint-disable-next-line no-await-in-loop
if (await isBinUptoDate(pythonBinPath, MinVersions.python!)) {
return pythonBinPath
}
} }
} catch { } catch {
// fall through // fall through
@ -166,22 +168,24 @@ async function findOrSetupPip(foundPython: string) {
} }
async function findPip() { async function findPip() {
const foundBins = (await Promise.all(["pip3", "pip"].map(isPipUptoDate))).filter( for (const pipCandidate of ["pip3", "pip"]) {
(bin) => bin !== undefined // eslint-disable-next-line no-await-in-loop
) as string[] const maybePip = await isPipUptoDate(pipCandidate)
if (maybePip !== undefined) {
if (foundBins.length === 0) { return maybePip
return undefined }
} }
return undefined
return foundBins[0]
} }
async function isPipUptoDate(pip: string) { async function isPipUptoDate(pip: string) {
try { try {
const pipPath: string | null = await which(pip, { nothrow: true }) const pipPaths = (await which(pip, { nothrow: true, all: true })) ?? []
if (pipPath !== null && (await isBinUptoDate(pipPath, MinVersions.pip!))) { for (const pipPath of pipPaths) {
return pipPath // eslint-disable-next-line no-await-in-loop
if (pipPath !== null && (await isBinUptoDate(pipPath, MinVersions.pip!))) {
return pipPath
}
} }
} catch { } catch {
// fall through // fall through