From 55e744ac63779a47a683437f08d14bedd7a93bf1 Mon Sep 17 00:00:00 2001 From: zouchengfu Date: Fri, 24 Apr 2026 22:53:16 +0800 Subject: [PATCH] fix(scripts): prefer uv pip over python -m pip in start_tour.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit uv-managed .venv environments may have pip disabled (PEP 668 / uv's default hardening). Running `python -m pip install` inside such a venv raises a CalledProcessError even though uv itself is available. Introduce `_resolve_pip_cmd()` which checks `shutil.which("uv")` at startup: - uv found → use ["uv", "pip"] (uv auto-detects the active venv) - uv absent → fall back to [_PYTHON, "-m", "pip"] (no regression) All pip invocations in `_bootstrap()` and `_install_commands()` now use `_PIP_CMD` instead of the hard-coded `[_PYTHON, "-m", "pip"]` prefix. --- scripts/start_tour.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/start_tour.py b/scripts/start_tour.py index 444dbae4e..53242ddb1 100644 --- a/scripts/start_tour.py +++ b/scripts/start_tour.py @@ -41,6 +41,21 @@ def _resolve_python() -> str: _PYTHON: str = _resolve_python() + +def _resolve_pip_cmd() -> list[str]: + """Return the best available pip invocation for the current environment. + + Prefer ``uv pip`` when uv is on PATH (uv-managed venvs may have pip + disabled). Fall back to ``python -m pip`` otherwise. + """ + uv = shutil.which("uv") + if uv: + return [uv, "pip"] + return [_PYTHON, "-m", "pip"] + + +_PIP_CMD: list[str] = _resolve_pip_cmd() + _BOOTSTRAP_PACKAGES = [ ("yaml", "PyYAML>=6.0"), ] @@ -61,7 +76,7 @@ def _bootstrap() -> None: return print(f" Installing bootstrap dependencies: {', '.join(missing)} ...") subprocess.check_call( - [_PYTHON, "-m", "pip", "install", *missing, "-q"], + [*_PIP_CMD, "install", *missing, "-q"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) @@ -341,12 +356,12 @@ def _install_commands( cmds: list[tuple[list[str], Path]] = [] for req in PROFILE_COMMANDS[profile]: - cmds.append(([_PYTHON, "-m", "pip", "install", "-r", req], PROJECT_ROOT)) + cmds.append(([*_PIP_CMD, "install", "-r", req], PROJECT_ROOT)) if include_math_animator: cmds.append( - ([_PYTHON, "-m", "pip", "install", "-r", MATH_ANIMATOR_REQUIREMENTS], PROJECT_ROOT) + ([*_PIP_CMD, "install", "-r", MATH_ANIMATOR_REQUIREMENTS], PROJECT_ROOT) ) - cmds.append(([_PYTHON, "-m", "pip", "install", "-e", ".", "--no-deps"], PROJECT_ROOT)) + cmds.append(([*_PIP_CMD, "install", "-e", ".", "--no-deps"], PROJECT_ROOT)) if profile.startswith("web"): cmds.append(([_get_npm_command(), "install"], PROJECT_ROOT / "web")) return cmds