Skip to content

Commit b543954

Browse files
committed
fix: check all the python/pip binaries on the PATH
1 parent d841abd commit b543954

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

dist/node12/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node12/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/python/python.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,14 @@ async function setupPythonSystem(setupDir: string, version: string) {
121121
}
122122

123123
async function findPython(binDir?: string) {
124-
const foundBins = (
125-
await Promise.all(["python3", "python"].map((pythonBin) => isPythonUpToDate(pythonBin, binDir)))
126-
).filter((bin) => bin !== undefined) as string[]
127-
128-
if (foundBins.length === 0) {
129-
return undefined
124+
for (const pythonBin of ["python3", "python"]) {
125+
// eslint-disable-next-line no-await-in-loop
126+
const foundPython = await isPythonUpToDate(pythonBin, binDir)
127+
if (foundPython !== undefined) {
128+
return foundPython
129+
}
130130
}
131-
132-
return foundBins[0]
131+
return undefined
133132
}
134133

135134
async function isPythonUpToDate(candidate: string, binDir?: string) {
@@ -142,9 +141,12 @@ async function isPythonUpToDate(candidate: string, binDir?: string) {
142141
}
143142
}
144143
}
145-
const pythonBinPath: string | null = await which(candidate, { nothrow: true })
146-
if (pythonBinPath !== null && (await isBinUptoDate(pythonBinPath, MinVersions.python!))) {
147-
return pythonBinPath
144+
const pythonBinPaths = (await which(candidate, { nothrow: true, all: true })) ?? []
145+
for (const pythonBinPath of pythonBinPaths) {
146+
// eslint-disable-next-line no-await-in-loop
147+
if (await isBinUptoDate(pythonBinPath, MinVersions.python!)) {
148+
return pythonBinPath
149+
}
148150
}
149151
} catch {
150152
// fall through
@@ -166,22 +168,24 @@ async function findOrSetupPip(foundPython: string) {
166168
}
167169

168170
async function findPip() {
169-
const foundBins = (await Promise.all(["pip3", "pip"].map(isPipUptoDate))).filter(
170-
(bin) => bin !== undefined
171-
) as string[]
172-
173-
if (foundBins.length === 0) {
174-
return undefined
171+
for (const pipCandidate of ["pip3", "pip"]) {
172+
// eslint-disable-next-line no-await-in-loop
173+
const maybePip = await isPipUptoDate(pipCandidate)
174+
if (maybePip !== undefined) {
175+
return maybePip
176+
}
175177
}
176-
177-
return foundBins[0]
178+
return undefined
178179
}
179180

180181
async function isPipUptoDate(pip: string) {
181182
try {
182-
const pipPath: string | null = await which(pip, { nothrow: true })
183-
if (pipPath !== null && (await isBinUptoDate(pipPath, MinVersions.pip!))) {
184-
return pipPath
183+
const pipPaths = (await which(pip, { nothrow: true, all: true })) ?? []
184+
for (const pipPath of pipPaths) {
185+
// eslint-disable-next-line no-await-in-loop
186+
if (pipPath !== null && (await isBinUptoDate(pipPath, MinVersions.pip!))) {
187+
return pipPath
188+
}
185189
}
186190
} catch {
187191
// fall through

0 commit comments

Comments
 (0)