fix: manually memoize getPython

This commit is contained in:
Amin Yahyaabadi 2024-09-17 15:49:19 -07:00
parent 99db11072d
commit 3a8e462ed6
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
6 changed files with 18 additions and 11 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

View File

@ -26,7 +26,11 @@ import { isBinUptoDate } from "../utils/setup/version.js"
import { unique } from "../utils/std/index.js"
import { MinVersions } from "../versions/default_versions.js"
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
export async function setupPython(
version: string,
setupDir: string,
arch: string,
): Promise<InstallationInfo & { bin: string }> {
const installInfo = await findOrSetupPython(version, setupDir, arch)
assert(installInfo.bin !== undefined)
const foundPython = installInfo.bin
@ -41,7 +45,7 @@ export async function setupPython(version: string, setupDir: string, arch: strin
await setupWheel(foundPython)
return installInfo
return installInfo as InstallationInfo & { bin: string }
}
async function setupPipx(foundPython: string) {

View File

@ -154,14 +154,17 @@ async function getPipxBinDir_() {
}
const getPipxBinDir = memoize(getPipxBinDir_, { promise: true })
async function getPython_(): Promise<string> {
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
if (pythonBin === undefined) {
throw new Error("Python binary was not found")
/* eslint-disable require-atomic-updates */
let pythonBin: string | undefined
async function getPython(): Promise<string> {
if (pythonBin !== undefined) {
return pythonBin
}
pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
return pythonBin
}
const getPython = memoize(getPython_, { promise: true })
type PipxShowType = {
venvs: Record<string, {