Skip to content

Commit 3a8e462

Browse files
committed
fix: manually memoize getPython
1 parent 99db110 commit 3a8e462

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

dist/legacy/setup-cpp.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

+1-1
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

+1-1
Large diffs are not rendered by default.

src/python/python.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import { isBinUptoDate } from "../utils/setup/version.js"
2626
import { unique } from "../utils/std/index.js"
2727
import { MinVersions } from "../versions/default_versions.js"
2828

29-
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
29+
export async function setupPython(
30+
version: string,
31+
setupDir: string,
32+
arch: string,
33+
): Promise<InstallationInfo & { bin: string }> {
3034
const installInfo = await findOrSetupPython(version, setupDir, arch)
3135
assert(installInfo.bin !== undefined)
3236
const foundPython = installInfo.bin
@@ -41,7 +45,7 @@ export async function setupPython(version: string, setupDir: string, arch: strin
4145

4246
await setupWheel(foundPython)
4347

44-
return installInfo
48+
return installInfo as InstallationInfo & { bin: string }
4549
}
4650

4751
async function setupPipx(foundPython: string) {

src/utils/setup/setupPipPack.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,17 @@ async function getPipxBinDir_() {
154154
}
155155
const getPipxBinDir = memoize(getPipxBinDir_, { promise: true })
156156

157-
async function getPython_(): Promise<string> {
158-
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
159-
if (pythonBin === undefined) {
160-
throw new Error("Python binary was not found")
157+
/* eslint-disable require-atomic-updates */
158+
let pythonBin: string | undefined
159+
160+
async function getPython(): Promise<string> {
161+
if (pythonBin !== undefined) {
162+
return pythonBin
161163
}
164+
165+
pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
162166
return pythonBin
163167
}
164-
const getPython = memoize(getPython_, { promise: true })
165168

166169
type PipxShowType = {
167170
venvs: Record<string, {

0 commit comments

Comments
 (0)