From 93e61ef9364c9b119ce8d2170803840a0f7cf68c Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Oct 2026 10:27:21 +0300 Subject: [PATCH] Port regen: hand the tools a Python that runs python() returned shutil.which("python3"), which on Git for Windows is the Microsoft Store stub (prints "Python", exits 49): every tool it launched failed before its first line. Probe python3, python and py and keep the first that is Python 3, once per process. Co-Authored-By: Hermes Agent (Nous Research) --- tests/test_port_regen.py | 9 +++++++++ tools/port_regen.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_port_regen.py b/tests/test_port_regen.py index c52499417..5253b6221 100644 --- a/tests/test_port_regen.py +++ b/tests/test_port_regen.py @@ -1,3 +1,4 @@ +import subprocess import unittest from tools import port_regen as regen @@ -48,5 +49,13 @@ class CompileErrorTests(unittest.TestCase): self.assertEqual(regen.compile_errors("expected the root's order to differ"), []) +class InterpreterTests(unittest.TestCase): + def test_python_is_an_interpreter_that_runs(self): + found = regen.python() + done = subprocess.run([found, "-c", "import sys; sys.exit(sys.version_info < (3,))"], + capture_output=True) + self.assertEqual(done.returncode, 0, f"{found} is not a Python 3 that runs") + + if __name__ == "__main__": unittest.main() diff --git a/tools/port_regen.py b/tools/port_regen.py index 4d69b0986..58f33d52e 100644 --- a/tools/port_regen.py +++ b/tools/port_regen.py @@ -124,8 +124,23 @@ def prepare_local(root, version, found, store): run([python(), "tools/lab.py", "prepare", "--minecraft-dir", tree, "--server-jar", found["server"]], root) +_PYTHON = None + + def python(): - return shutil.which("python3") or "python3" + """The interpreter to run the other tools with. Git for Windows puts a + `python3` on PATH that is only the Store stub: it prints "Python" and exits + 49, so probe the names and keep the first one that runs Python 3.""" + global _PYTHON + if _PYTHON is None: + _PYTHON = "python3" + for name in ("python3", "python", "py"): + found = shutil.which(name) + probe = [found, "-c", "import sys; sys.exit(sys.version_info < (3,))"] if found else None + if probe and subprocess.run(probe, capture_output=True).returncode == 0: + _PYTHON = found + break + return _PYTHON class Failed(RuntimeError):