fix: choose the python binary directory based on the existence

This commit is contained in:
Amin Yahyaabadi 2022-11-04 19:04:04 -07:00
parent 0f4b1a6238
commit e376f26cd2
6 changed files with 12 additions and 15 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

@ -149,12 +149,5 @@ export async function addPythonBaseExecPrefix(python: string) {
// add the directories to the path // add the directories to the path
await Promise.all(dirs.map((dir) => addPath(dir))) await Promise.all(dirs.map((dir) => addPath(dir)))
// the last directory is the bin directory (not empty) return dirs
const foundBinDir = dirs.pop()
if (foundBinDir === undefined) {
warning("The binary directory for pip dependencies could not be found")
}
return foundBinDir!
} }

View File

@ -3,9 +3,11 @@ import execa from "execa"
import { info } from "@actions/core" import { info } from "@actions/core"
import { addPythonBaseExecPrefix, setupPythonAndPip } from "../../python/python" import { addPythonBaseExecPrefix, setupPythonAndPip } from "../../python/python"
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { existsSync } from "fs"
import { addExeExt, join } from "patha"
let python: string | undefined let python: string | undefined
let binDir: string | undefined let binDirs: string[] | undefined
/** A function that installs a package using pip */ /** A function that installs a package using pip */
export async function setupPipPack(name: string, version?: string): Promise<InstallationInfo> { export async function setupPipPack(name: string, version?: string): Promise<InstallationInfo> {
@ -19,9 +21,11 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
stdio: "inherit", stdio: "inherit",
}) })
if (binDir === undefined) { if (binDirs === undefined) {
binDir = await addPythonBaseExecPrefix(python) binDirs = await addPythonBaseExecPrefix(python)
} }
const binDir = binDirs.find((dir) => existsSync(join(dir, addExeExt(name)))) ?? binDirs.pop()!
return { binDir } return { binDir }
} }