Skip to content

Commit 623216a

Browse files
committed
fix: handle the MacOS/Linux exec prefix paths
1 parent 2dde08d commit 623216a

File tree

6 files changed

+38
-18
lines changed

6 files changed

+38
-18
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { dirname, join } from "patha"
1212
import { hasDnf } from "../utils/env/hasDnf"
1313
import { setupDnfPack } from "../utils/setup/setupDnfPack"
1414
import { isUbuntu } from "../utils/env/isUbuntu"
15+
import { getExecOutput } from "@actions/exec"
16+
import { existsSync } from "fs"
1517

1618
export async function setupPython(version: string, setupDir: string, arch: string) {
1719
if (ciDetect() !== "github-actions") {
@@ -75,3 +77,33 @@ export async function setupPythonViaSystem(
7577
}
7678
}
7779
}
80+
81+
export async function addPythonBaseExecPrefix(python: string) {
82+
let dirs: string[] = []
83+
84+
// detection based on the platform
85+
if (process.platform === "linux") {
86+
dirs.push("/home/runner/.local/bin/")
87+
} else if (process.platform === "darwin") {
88+
dirs.push("/usr/local/bin/")
89+
}
90+
91+
// detection using python.sys
92+
const base_exec_prefix = (await getExecOutput(`${python} -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim()
93+
dirs.push(join(base_exec_prefix, "Scripts"), join(base_exec_prefix, "Scripts", "bin"))
94+
95+
// exclude the non existing ones
96+
dirs = dirs.filter((dir) => existsSync(dir))
97+
98+
// add the directories to the path
99+
await Promise.all(dirs.map((dir) => addPath(dir)))
100+
101+
// the last directory is the bin directory (not empty)
102+
const foundBinDir = dirs.pop()
103+
104+
if (foundBinDir === undefined) {
105+
warning("The binary directory for pip dependencies could not be found")
106+
}
107+
108+
return foundBinDir!
109+
}

src/utils/setup/setupPipPack.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/* eslint-disable require-atomic-updates */
2-
import { getExecOutput } from "@actions/exec"
32
import execa from "execa"
43
import which from "which"
54
import { info } from "@actions/core"
6-
import { addPath } from "../env/addEnv"
7-
import { setupPython } from "../../python/python"
5+
import { addPythonBaseExecPrefix, setupPython } from "../../python/python"
86
import { isBinUptoDate } from "./version"
9-
import { join } from "patha"
107
import { getVersion } from "../../versions/versions"
118
import { InstallationInfo } from "./setupBin"
129
import { setupAptPack } from "./setupAptPack"
@@ -65,17 +62,8 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
6562
})
6663

6764
if (binDir === undefined) {
68-
binDir = await addPythonBaseExecPrefix()
65+
binDir = await addPythonBaseExecPrefix(python)
6966
}
7067

7168
return { binDir }
7269
}
73-
74-
async function addPythonBaseExecPrefix() {
75-
const base_exec_prefix = join(
76-
(await getExecOutput(`${python} -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim(),
77-
"Scripts"
78-
)
79-
await addPath(base_exec_prefix)
80-
return base_exec_prefix
81-
}

0 commit comments

Comments
 (0)