mirror of
https://github.com/github/spec-kit.git
synced 2026-07-11 18:59:53 +08:00
fix(integrations): skip Windows Store python3 alias stub in resolve_python_interpreter (#3385)
* fix(integrations): skip Windows Store python3 alias stub in resolve_python_interpreter
On stock Windows, python3 on PATH is the Microsoft Store App Execution
Alias stub: it exists but only prints an installer hint and exits
non-zero, so generated {SCRIPT} invocations for the py script type were
broken. Verify the found interpreter actually runs before accepting it,
on Windows only, mirroring the parse-success-not-availability approach
of #3312/#3320 for the sh scripts. POSIX keeps the plain existence
check. sys.executable remains the fallback and is always live.
Fixes #3383
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(integrations): probe interpreter isolated and without site, discard I/O
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* test: pin POSIX platform in PATH-resolution tests
The tests fake shutil.which with POSIX paths; on Windows CI the real
sys.platform made the stub probe run against those fake paths and
fall through to sys.executable.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import os
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from abc import ABC
|
||||
from dataclasses import dataclass
|
||||
@@ -604,10 +605,42 @@ class IntegrationBase(ABC):
|
||||
if candidate.exists():
|
||||
return relative
|
||||
for name in ("python3", "python"):
|
||||
if shutil.which(name):
|
||||
return name
|
||||
found = shutil.which(name)
|
||||
if not found:
|
||||
continue
|
||||
# On Windows, python3/python on PATH may be the Microsoft
|
||||
# Store App Execution Alias stub: it exists but only prints
|
||||
# an installer hint and exits non-zero, so existence is not
|
||||
# enough (see #3304 for the same defect in the sh scripts).
|
||||
if sys.platform == "win32" and not IntegrationBase._interpreter_runs(
|
||||
found
|
||||
):
|
||||
continue
|
||||
return name
|
||||
return sys.executable or "python3"
|
||||
|
||||
@staticmethod
|
||||
def _interpreter_runs(path: str) -> bool:
|
||||
"""Return True when *path* executes as a Python interpreter.
|
||||
|
||||
Runs isolated (``-I``) without ``site`` (``-S``) and discards
|
||||
I/O so the probe is a fast liveness check that cannot trigger
|
||||
``sitecustomize``/user startup hooks.
|
||||
"""
|
||||
try:
|
||||
return (
|
||||
subprocess.run(
|
||||
[path, "-I", "-S", "-c", ""],
|
||||
stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=15,
|
||||
).returncode
|
||||
== 0
|
||||
)
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def process_template(
|
||||
content: str,
|
||||
@@ -1089,7 +1122,6 @@ class TomlIntegration(IntegrationBase):
|
||||
# YamlIntegration — YAML-format agents (Goose)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class YamlIntegration(IntegrationBase):
|
||||
"""Concrete base for integrations that use YAML recipe format.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user