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) <[email protected]>
This commit is contained in:
AlexanderandHermes Agent committed 2026-10-28 10:27:21 +03:00
1 parent b6c936f82b
commit 93e61ef936
2 files changed
+25 -1

No files matched your search

+9
View File
@@ -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()
+16 -1
View File
@@ -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):