Skip to content

Commit

Permalink
fix: manually memoize getPython
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 17, 2024
1 parent 99db110 commit 3a8e462
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/python/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions src/utils/setup/setupPipPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 3a8e462

Please sign in to comment.