From d52642da971ed33ca4847fd93bab4becd4fb6087 Mon Sep 17 00:00:00 2001 From: Ankit Kotnala Date: Sat, 23 May 2026 21:16:06 +0530 Subject: [PATCH] Repaired incomplete local virtualenv setup --- scripts/xmem.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/scripts/xmem.js b/scripts/xmem.js index d9158de..93c1a0b 100644 --- a/scripts/xmem.js +++ b/scripts/xmem.js @@ -519,6 +519,33 @@ function ensurePrerequisites(skipPython = false) { } } +function pythonHasPip(pythonPath) { + return run(pythonPath, ["-m", "pip", "--version"], { capture: true, allowFailure: true }).status === 0; +} + +function ensureVirtualenv() { + const venvPython = venvPythonPath(); + if (!fs.existsSync(venvPython)) { + log("Creating XMem virtualenv"); + run(systemPythonCommand(), ["-m", "venv", path.join(root, ".venv")]); + } + + if (!pythonHasPip(venvPython)) { + log("Repairing XMem virtualenv pip"); + const result = run(venvPython, ["-m", "ensurepip", "--upgrade"], { + allowFailure: true, + }); + if (result.status !== 0 || !pythonHasPip(venvPython)) { + fail( + "XMem virtualenv was created, but pip is unavailable. Reinstall Python with venv/pip support, delete .venv, and rerun npm run setup.", + 2, + ); + } + } + + return venvPython; +} + function setupLooksComplete(reposDir) { return ( fs.existsSync(path.join(root, "pyproject.toml")) && @@ -586,11 +613,7 @@ function runSetup(args) { } if (!options.skipPythonInstall) { - const venvPython = venvPythonPath(); - if (!fs.existsSync(venvPython)) { - log("Creating XMem virtualenv"); - run(systemPythonCommand(), ["-m", "venv", path.join(root, ".venv")]); - } + const venvPython = ensureVirtualenv(); log("Installing XMem local dependencies"); run(venvPython, ["-m", "pip", "install", "--upgrade", "pip"]); run(venvPython, ["-m", "pip", "install", "-e", `${root}[local,dev]`]);