The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): the pinned Windows Python also answers to python3
ethernet190c0b7f65e2
diff --git a/pm/packages.py b/pm/packages.pyindex 2002a6d0684..c54fa87f2a6 100644--- a/pm/packages.py+++ b/pm/packages.py@@ -220,6 +220,10 @@ class Uv(_BionicDebArm, BinaryPackage, DebPackage):return github_release_tags("astral-sh/uv")+# The POSIX interpreter name the pinned Windows Python also answers to (see Python.stage).+WINDOWS_PYTHON3 = "python3.exe"++@registerclass Python(_BionicDebArm, BinaryPackage, DebPackage):"""The pinned interpreter for launchers and every PM-managed uv command.@@ -261,6 +265,28 @@ class Python(_BionicDebArm, BinaryPackage, DebPackage):# old bundle-time drop did) makes doctor's re-hash mismatch.if target == "win32-arm64":(staged / "vcruntime140_1.dll").unlink(missing_ok=True)+ # python-build-standalone's Windows build ships python.exe only, so `python3` (npm and+ # vitest helpers, POSIX-minded scripts) resolves past the activated PATH to the Microsoft+ # Store's App Execution Alias stub, which installs nothing and fails. python.exe is a+ # small launcher of pythonXY.dll that finds its home from its own directory, so a copy+ # under the POSIX name is the same interpreter. Staged before publish, so the recorded+ # tree digest covers it.+ if target.startswith("win32"):+ shutil.copy2(staged / "python.exe", staged / WINDOWS_PYTHON3)++ def verify(self, entry: Path, target: str) -> str:+ reason = super().verify(entry, target)+ if reason or not target.startswith("win32"):+ return reason+ # An entry staged before python3.exe existed fails here, so an explicit install+ # (activation's setup) restages it once; startup's facts check never calls verify.+ alias = entry / WINDOWS_PYTHON3+ try:+ if alias.read_bytes() == (entry / "python.exe").read_bytes():+ return ""+ except OSError:+ return f"{WINDOWS_PYTHON3} is missing beside python.exe"+ return f"{WINDOWS_PYTHON3} differs from python.exe"def fetch_url(self, version: str, target: str) -> str:if target == "linux-arm64-bionic":diff --git a/tests/pm/test_pm_core.py b/tests/pm/test_pm_core.pyindex 8115ab64a31..7d17b46db9d 100644--- a/tests/pm/test_pm_core.py+++ b/tests/pm/test_pm_core.py@@ -769,6 +769,7 @@ def test_python_stage_drops_unloadable_x64_vc_runtime_on_arm64(monkeypatch, tmp_staged = tmp_path / "staged"staged.mkdir()+ (staged / "python.exe").write_bytes(b"launcher")(staged / "vcruntime140_1.dll").write_bytes(b"x64")(staged / "vcruntime140.dll").write_bytes(b"arm64")@@ -784,6 +785,7 @@ def test_python_stage_keeps_vc_runtimes_on_other_targets(monkeypatch, tmp_path):staged = tmp_path / "staged"staged.mkdir()+ (staged / "python.exe").write_bytes(b"launcher")(staged / "vcruntime140_1.dll").write_bytes(b"x64")monkeypatch.setattr("hermes_cli.macos_signing.sign_managed_python", lambda p: False)@@ -792,6 +794,39 @@ def test_python_stage_keeps_vc_runtimes_on_other_targets(monkeypatch, tmp_path):assert (staged / "vcruntime140_1.dll").is_file()[email protected]("target", ["win32-x64", "win32-arm64"])+def test_windows_python_also_answers_to_python3(monkeypatch, tmp_path, target):+ """`python3` must reach the pinned interpreter, not the Microsoft Store alias stub."""+ from pm.registry import get_package++ python = get_package("python")+ staged = tmp_path / "staged"+ staged.mkdir()+ (staged / "python.exe").write_bytes(b"launcher")+ monkeypatch.setattr("hermes_cli.macos_signing.sign_managed_python", lambda p: False)+ python.stage(None, staged, "3.14.7", target)+ assert (staged / "python3.exe").read_bytes() == b"launcher"+ assert python.verify(staged, target) == ""+ # An entry staged before the copy existed (or with a stale one) restages on install.+ (staged / "python3.exe").write_bytes(b"older launcher")+ assert "differs" in python.verify(staged, target)+ (staged / "python3.exe").unlink()+ assert "python3.exe is missing" in python.verify(staged, target)+++def test_python3_alias_is_windows_only(monkeypatch, tmp_path):+ from pm.registry import get_package++ python = get_package("python")+ staged = tmp_path / "staged"+ (staged / "bin").mkdir(parents=True)+ (staged / "bin/python3").write_bytes(b"interpreter")+ monkeypatch.setattr("hermes_cli.macos_signing.sign_managed_python", lambda p: False)+ python.stage(None, staged, "3.14.7", "linux-x64")+ assert not (staged / "python3.exe").exists()+ assert python.verify(staged, "linux-x64") == ""++def test_verify_missing_binary_reports_path_and_listing(tmp_path):"""A missing binary must say which path is missing and what theentry actually contains — the diagnosis that exposes a bad pin."""