fix: memoize addPythonBaseExecPrefix

This commit is contained in:
Amin Yahyaabadi 2023-06-28 15:22:03 -07:00
parent 08aaab1859
commit f6ebfc1d77
11 changed files with 77 additions and 65 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -98,6 +98,7 @@
"gen-readme": "^1.6.0", "gen-readme": "^1.6.0",
"is-url-online": "^1.5.0", "is-url-online": "^1.5.0",
"jest": "^29.5.0", "jest": "^29.5.0",
"micro-memoize": "^4.1.2",
"mri": "^1.2.0", "mri": "^1.2.0",
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1", "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
"npm-check-updates": "^16.10.13", "npm-check-updates": "^16.10.13",

View File

@ -113,6 +113,9 @@ importers:
jest: jest:
specifier: ^29.5.0 specifier: ^29.5.0
version: 29.5.0(@types/node@20.3.2)(ts-node@10.9.1) version: 29.5.0(@types/node@20.3.2)(ts-node@10.9.1)
micro-memoize:
specifier: ^4.1.2
version: 4.1.2
mri: mri:
specifier: ^1.2.0 specifier: ^1.2.0
version: 1.2.0 version: 1.2.0
@ -7711,6 +7714,10 @@ packages:
engines: {node: '>= 8'} engines: {node: '>= 8'}
dev: true dev: true
/micro-memoize@4.1.2:
resolution: {integrity: sha512-+HzcV2H+rbSJzApgkj0NdTakkC+bnyeiUxgT6/m7mjcz1CmM22KYFKp+EVj1sWe4UYcnriJr5uqHQD/gMHLD+g==}
dev: true
/micromark-core-commonmark@1.1.0: /micromark-core-commonmark@1.1.0:
resolution: {integrity: sha512-BgHO1aRbolh2hcrzL2d1La37V0Aoz73ymF8rAcKnohLy93titmv62E0gP8Hrx9PKcKrqCZ1BbLGbP3bEhoXYlw==} resolution: {integrity: sha512-BgHO1aRbolh2hcrzL2d1La37V0Aoz73ymF8rAcKnohLy93titmv62E0gP8Hrx9PKcKrqCZ1BbLGbP3bEhoXYlw==}
dependencies: dependencies:

View File

@ -1,24 +1,25 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { getExecOutput } from "@actions/exec"
import assert from "assert"
import { GITHUB_ACTIONS } from "ci-info"
import { info, warning } from "ci-log"
import { execaSync } from "execa"
import memoize from "micro-memoize"
import { dirname, join } from "patha"
import which from "which"
import { addPath } from "../utils/env/addEnv" import { addPath } from "../utils/env/addEnv"
import { hasDnf } from "../utils/env/hasDnf"
import { isArch } from "../utils/env/isArch"
import { isUbuntu } from "../utils/env/isUbuntu"
import { setupAptPack } from "../utils/setup/setupAptPack" import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack" import { InstallationInfo } from "../utils/setup/setupBin"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { GITHUB_ACTIONS } from "ci-info"
import { warning, info } from "ci-log"
import { isArch } from "../utils/env/isArch"
import which from "which"
import { InstallationInfo } from "../utils/setup/setupBin"
import { dirname, join } from "patha"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack" import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu" import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { getExecOutput } from "@actions/exec"
import { isBinUptoDate } from "../utils/setup/version" import { isBinUptoDate } from "../utils/setup/version"
import { execaSync } from "execa"
import { unique } from "../utils/std" import { unique } from "../utils/std"
import { DefaultVersions } from "../versions/default_versions" import { DefaultVersions } from "../versions/default_versions"
import assert from "assert"
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> { export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
const installInfo = await findOrSetupPython(version, setupDir, arch) const installInfo = await findOrSetupPython(version, setupDir, arch)
@ -204,7 +205,7 @@ function setupWheel(foundPython: string) {
execaSync(foundPython, ["-m", "pip", "install", "-U", "wheel"], { stdio: "inherit" }) execaSync(foundPython, ["-m", "pip", "install", "-U", "wheel"], { stdio: "inherit" })
} }
export async function addPythonBaseExecPrefix(python: string) { async function addPythonBaseExecPrefix_raw(python: string) {
const dirs: string[] = [] const dirs: string[] = []
// detection based on the platform // detection based on the platform
@ -222,3 +223,10 @@ export async function addPythonBaseExecPrefix(python: string) {
// remove duplicates // remove duplicates
return unique(dirs) return unique(dirs)
} }
/**
* Add the base exec prefix to the PATH. This is required for Conan, Meson, etc. to work properly.
*
* The answer is cached for subsequent calls
*/
export const addPythonBaseExecPrefix = memoize(addPythonBaseExecPrefix_raw)

View File

@ -10,7 +10,6 @@ import { getVersion } from "../../versions/versions"
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
let python: string | undefined let python: string | undefined
let execPaths: string[] | undefined
/** A function that installs a package using pip */ /** A function that installs a package using pip */
export async function setupPipPack(name: string, version?: string): Promise<InstallationInfo> { export async function setupPipPack(name: string, version?: string): Promise<InstallationInfo> {
@ -24,10 +23,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
stdio: "inherit", stdio: "inherit",
}) })
if (execPaths === undefined) { const execPaths = await addPythonBaseExecPrefix(python)
execPaths = await addPythonBaseExecPrefix(python)
}
const binDir = await findBinDir(execPaths, name) const binDir = await findBinDir(execPaths, name)
await addPath(binDir) await addPath(binDir)