Merge pull request #3080 from Domanffe/fix/port-regen-python-that-runs

🤖 Agent: read the diff at 93e61ef93: port_regen.python() probes python3/python/py and keeps the first that runs Python 3 (cached), with a test. verify green. Queued for the merger.
This commit is contained in:
Ludovic Marie
2026-10-28 19:30:16 +01:00
committed by GitHub
2 changed files with 25 additions and 1 deletions
+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):