fix: fisrt check python binary instead of python3

To avoid preferring brew over system python
This commit is contained in:
Amin Yahyaabadi 2024-09-17 17:17:23 -07:00
parent 381411326c
commit d316735ce5
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
6 changed files with 10 additions and 10 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

@ -183,7 +183,7 @@ async function setupPythonSystem(setupDir: string, version: string) {
} }
async function findPython(binDir?: string) { async function findPython(binDir?: string) {
for (const pythonBin of ["python3", "python"]) { for (const pythonBin of ["python", "python3"]) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
const foundPython = await isPythonUpToDate(pythonBin, binDir) const foundPython = await isPythonUpToDate(pythonBin, binDir)
if (foundPython !== undefined) { if (foundPython !== undefined) {
@ -215,10 +215,8 @@ async function isPythonUpToDate(candidate: string, binDir?: string) {
try { try {
if (binDir !== undefined) { if (binDir !== undefined) {
const pythonBinPath = join(binDir, addExeExt(candidate)) const pythonBinPath = join(binDir, addExeExt(candidate))
if (await pathExists(pythonBinPath)) { if (await pathExists(pythonBinPath) && await isBinUptoDate(pythonBinPath, MinVersions.python!)) {
if (await isBinUptoDate(pythonBinPath, MinVersions.python!)) { return pythonBinPath
return pythonBinPath
}
} }
} }
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition

View File

@ -50,6 +50,7 @@ export async function setupPipPackWithPython(
const { usePipx = true, user = true, upgrade = false, isLibrary = false } = options const { usePipx = true, user = true, upgrade = false, isLibrary = false } = options
const isPipx = usePipx && !isLibrary && (await hasPipx(givenPython)) const isPipx = usePipx && !isLibrary && (await hasPipx(givenPython))
const pip = isPipx ? "pipx" : "pip" const pip = isPipx ? "pipx" : "pip"
// 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
@ -104,7 +105,8 @@ async function finishPipPackageInstall(givenPython: string, name: string) {
} }
export async function hasPipx(givenPython: string) { export async function hasPipx(givenPython: string) {
return (await execa(givenPython, ["-m", "pipx", "--help"], { stdio: "ignore", reject: false })).exitCode === 0 const res = await execa(givenPython, ["-m", "pipx", "--help"], { stdio: "ignore", reject: false })
return res.exitCode === 0
} }
async function getPipxHome_() { async function getPipxHome_() {