From 1e1c868e5ff3401ae02ca73499c1029db0b74451 Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Wed, 12 Aug 2026 22:18:31 +0700 Subject: [PATCH] fix(core): a venv is never externally managed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found while building a below-floor pip to verify P0-10: `pipdock pip-upgrade` refused a freshly created virtual environment with PD-ENV-002, the code that exists to protect system Pythons from being mutated. A venv has no stdlib of its own. `sysconfig.get_path("stdlib")` resolves to the *base* installation, so `_externally_managed()` was finding the base's marker and reporting it as the venv's. Every venv created from a Python that ships EXTERNALLY-MANAGED — uv-managed builds, Debian, Homebrew, Fedora — declared itself unmutable, and PipDock refused to update, install into, uninstall from or upgrade pip in the one kind of environment PEP 668 tells users to create. uv-managed Pythons are the case that found it, and PipDock ships uv support. pip's own check_externally_managed opens with exactly this early return before it looks for the file; the probe was missing the first half of the rule and keeping the second. The information was already three functions away — `_hidden_user_site` tests the same expression, and the probe reports it as `is_venv`. Wider than P1, and fixed here because P1 is what made it reachable and because a mutation tool that will not mutate anything is not a bug to route around. The CI gate lands with the rest of P1's; it plants a marker rather than hoping for one, and asserts both directions — a fix that simply stopped looking would pass the venv half and silently break PD-ENV-002. Co-Authored-By: Claude Opus 5 --- crates/pipdock-core/src/probe.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/pipdock-core/src/probe.py b/crates/pipdock-core/src/probe.py index 342027b..9f39c8f 100644 --- a/crates/pipdock-core/src/probe.py +++ b/crates/pipdock-core/src/probe.py @@ -58,7 +58,23 @@ def _externally_managed() -> bool: The marker sits next to the stdlib in the `stdlib` scheme path. Its mere presence is what pip keys off, so PipDock does the same -- contents are not parsed. Drives PD-ENV-002. + + **A virtual environment is never externally managed**, and returning early is + not an optimisation. A venv has no stdlib of its own: `sysconfig.get_path` + resolves to the *base* installation, so every venv created from a Python that + ships the marker -- uv-managed builds, Debian, Homebrew, Fedora -- reported + itself as managed and PipDock refused to mutate it. Found by making a venv + from a uv-managed 3.11 and watching `pip-upgrade` refuse with PD-ENV-002 on + an environment whose whole purpose is being safe to install into. + + This mirrors pip's own `check_externally_managed`, which opens with the same + `running_under_virtualenv()` early return before it looks for the file. The + `platstdlib` candidate below is a deliberate superset of pip's single + `stdlib` check; on Windows they resolve to the same directory. """ + if sys.prefix != sys.base_prefix: + return False + candidates = [] for key in ("stdlib", "platstdlib"): try: