From ecb7cdd1204da867f69570be27dbd87ca2c91700 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 16 Sep 2021 11:49:09 -0500 Subject: [PATCH] fix: fix pip installation path for macos and windows --- src/utils/setup/setupPipPack.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/utils/setup/setupPipPack.ts b/src/utils/setup/setupPipPack.ts index d8806410..c4500125 100644 --- a/src/utils/setup/setupPipPack.ts +++ b/src/utils/setup/setupPipPack.ts @@ -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