fix: use an absolute path to pip3 and python on windows

This commit is contained in:
Amin Yahyaabadi 2022-02-04 15:32:31 -08:00
parent 8daf6389ac
commit 488c981727
4 changed files with 22 additions and 28 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,6 @@ specifiers:
cross-spawn: ^7.0.3 cross-spawn: ^7.0.3
eslint-config-atomic: ^1.16.6 eslint-config-atomic: ^1.16.6
execa: ^5.1.1 execa: ^5.1.1
hasha: ^5.2.2
jest: ^27.4.7 jest: ^27.4.7
mri: ^1.2.0 mri: ^1.2.0
msvc-dev-cmd: git://github.com/aminya/msvc-dev-cmd#9f672c1 msvc-dev-cmd: git://github.com/aminya/msvc-dev-cmd#9f672c1
@ -41,7 +40,6 @@ dependencies:
'@actions/io': 1.1.1 '@actions/io': 1.1.1
'@actions/tool-cache': 1.7.1 '@actions/tool-cache': 1.7.1
execa: 5.1.1 execa: 5.1.1
hasha: 5.2.2
mri: 1.2.0 mri: 1.2.0
msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1 msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1
semver: 7.3.5 semver: 7.3.5
@ -4378,14 +4376,6 @@ packages:
minimalistic-assert: 1.0.1 minimalistic-assert: 1.0.1
dev: true dev: true
/hasha/5.2.2:
resolution: {integrity: sha512-Hrp5vIK/xr5SkeN2onO32H0MgNZ0f17HRNH39WfL0SYUNOTZ5Lz1TJ8Pajo/87dYGEFlLMm7mIc/k/s6Bvz9HQ==}
engines: {node: '>=8'}
dependencies:
is-stream: 2.0.1
type-fest: 0.8.1
dev: false
/highlight.js/10.4.1: /highlight.js/10.4.1:
resolution: {integrity: sha512-yR5lWvNz7c85OhVAEAeFhVCc/GV4C30Fjzc/rCP0aCWzc1UUOPUk55dK/qdwTZHBvMZo+eZ2jpk62ndX/xMFlg==} resolution: {integrity: sha512-yR5lWvNz7c85OhVAEAeFhVCc/GV4C30Fjzc/rCP0aCWzc1UUOPUk55dK/qdwTZHBvMZo+eZ2jpk62ndX/xMFlg==}
dev: true dev: true
@ -7771,6 +7761,7 @@ packages:
/type-fest/0.8.1: /type-fest/0.8.1:
resolution: {integrity: sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==} resolution: {integrity: sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==}
engines: {node: '>=8'} engines: {node: '>=8'}
dev: true
/typedarray-to-buffer/3.1.5: /typedarray-to-buffer/3.1.5:
resolution: {integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==} resolution: {integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==}

View File

@ -11,6 +11,7 @@ import { getVersion } from "../../default_versions"
import { untildify_user as untildify } from "../path/untildify" import { untildify_user as untildify } from "../path/untildify"
let pip: string | undefined let pip: string | undefined
let python: string = "python3"
let binDir: string | undefined let binDir: string | undefined
@ -18,22 +19,23 @@ let binDir: string | undefined
export async function setupPipPack(name: string, version?: string) { export async function setupPipPack(name: string, version?: string) {
// setup python and pip if needed // setup python and pip if needed
if (pip === undefined) { if (pip === undefined) {
if (which.sync("pip3", { nothrow: true }) !== null) { if (process.platform === "win32") {
pip = "pip3" const installationInfo = await setupPython(getVersion("python", undefined), untildify("python"), process.arch)
} else if (which.sync("pip", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) { if (installationInfo?.installDir !== undefined) {
pip = "pip" pip = join(installationInfo.installDir, "Scripts", "pip3.exe")
python = join(installationInfo.installDir, "python.exe")
} else {
pip = "pip3"
}
} else { } else {
await setupPython("3.x", "", process.arch) if (which.sync("pip3", { nothrow: true }) !== null) {
pip = "pip3" pip = "pip3"
} } else if (which.sync("pip", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) {
} pip = "pip"
if (process.platform === "win32") { } else {
try { await setupPython("3.x", "", process.arch)
// test if pip executable is working pip = "pip3"
await execa(pip, ["--version"], { stdio: "inherit" }) }
} catch (err) {
await setupPython(getVersion("python", undefined), untildify("python"), process.arch)
pip = "pip3"
} }
} }
@ -47,9 +49,10 @@ export async function setupPipPack(name: string, version?: string) {
} else if (process.platform === "darwin") { } else if (process.platform === "darwin") {
binDir = "/usr/local/bin/" binDir = "/usr/local/bin/"
} else { } else {
// windows or others
try { try {
binDir = join( binDir = join(
(await getExecOutput('python3 -c "import sys;print(sys.base_exec_prefix);"')).stdout.trim(), (await getExecOutput(`${python} -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim(),
"Scripts" "Scripts"
) )
} catch { } catch {