fix: fix pip installation path for macos and windows

This commit is contained in:
Amin Yahyaabadi 2021-09-16 11:49:09 -05:00
parent bf63dd58d3
commit ecb7cdd120
1 changed files with 11 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/* eslint-disable require-atomic-updates */
import { exec } from "@actions/exec"
import { exec, getExecOutput } from "@actions/exec"
import which from "which"
import { addPath, startGroup, endGroup } from "@actions/core"
import { setupPython } from "../../python/python"
@ -7,6 +7,8 @@ import { isBinUptoDate } from "./version"
let pip: string | undefined
let binDir: string | undefined
/** A function that installs a package using pip */
export async function setupPipPack(name: string, version?: string) {
// setup python and pip if needed
@ -26,17 +28,20 @@ export async function setupPipPack(name: string, version?: string) {
throw new Error(`Failed to install ${name} ${version}`)
}
let binDir: string | undefined
if (process.platform === "linux") {
try {
if (binDir === undefined) {
if (process.platform === "linux") {
binDir = "/home/runner/.local/bin/"
} else if (process.platform === "darwin") {
binDir = "/usr/local/bin/"
} else {
binDir = (await getExecOutput("python -c 'import sys; print(sys.base_exec_prefix)'")).stdout
}
try {
startGroup(`${binDir} to PATH`)
addPath(binDir)
} finally {
endGroup()
}
} else if (process.platform === "darwin") {
binDir = "/usr/local/bin/"
}
return binDir