Skip to content

Commit 04867b9

Browse files
committed
fix: use which if the pip package executable was not found
1 parent e376f26 commit 04867b9

File tree

7 files changed

+31
-14
lines changed

7 files changed

+31
-14
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: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { isBinUptoDate } from "../utils/setup/version"
1818
import { getVersion } from "../versions/versions"
1919
import assert from "assert"
2020
import execa from "execa"
21+
import { unique } from "../utils/std"
2122

2223
export async function setupPython(version: string, setupDir: string, arch: string) {
2324
if (ciDetect() !== "github-actions") {
@@ -129,7 +130,7 @@ export async function setupPythonAndPip(): Promise<string> {
129130
}
130131

131132
export async function addPythonBaseExecPrefix(python: string) {
132-
let dirs: string[] = []
133+
const dirs: string[] = []
133134

134135
// detection based on the platform
135136
if (process.platform === "linux") {
@@ -143,11 +144,6 @@ export async function addPythonBaseExecPrefix(python: string) {
143144
// any of these are possible depending on the operating system!
144145
dirs.push(join(base_exec_prefix, "Scripts"), join(base_exec_prefix, "Scripts", "bin"), join(base_exec_prefix, "bin"))
145146

146-
// exclude the non existing ones
147-
dirs = dirs.filter((dir) => existsSync(dir))
148-
149-
// add the directories to the path
150-
await Promise.all(dirs.map((dir) => addPath(dir)))
151-
152-
return dirs
147+
// remove duplicates
148+
return unique(dirs)
153149
}

src/utils/setup/setupPipPack.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { info } from "@actions/core"
44
import { addPythonBaseExecPrefix, setupPythonAndPip } from "../../python/python"
55
import { InstallationInfo } from "./setupBin"
66
import { existsSync } from "fs"
7-
import { addExeExt, join } from "patha"
7+
import { addExeExt, dirname, join } from "patha"
8+
import { addPath } from "../env/addEnv"
9+
import which from "which"
810

911
let python: string | undefined
1012
let binDirs: string[] | undefined
@@ -25,7 +27,23 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
2527
binDirs = await addPythonBaseExecPrefix(python)
2628
}
2729

28-
const binDir = binDirs.find((dir) => existsSync(join(dir, addExeExt(name)))) ?? binDirs.pop()!
30+
const binDir = findBinDir(binDirs, name)
31+
32+
await addPath(binDir)
2933

3034
return { binDir }
3135
}
36+
37+
function findBinDir(dirs: string[], name: string) {
38+
const foundDir = dirs.find((dir) => existsSync(join(dir, addExeExt(name))))
39+
if (foundDir !== undefined) {
40+
return foundDir
41+
}
42+
43+
const whichDir = which.sync(addExeExt(name), { nothrow: true })
44+
if (whichDir !== null) {
45+
return dirname(whichDir)
46+
}
47+
48+
return dirs[dirs.length - 1]
49+
}

src/utils/std/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function unique(dirs: string[]) {
2+
return [...new Set(dirs)]
3+
}

0 commit comments

Comments
 (0)