Skip to content

Commit be1b606

Browse files
stonebigclaude
andcommitted
piptree: record the no-subprocess constraint
piptree runs inside JupyterLite/Pyodide, where no process can be spawned. PipData, pip_list, down and up are pure importlib.metadata + pathlib today; only Distribution, -md, -i and -u spawn, and those are Windows- only. Nothing enforced that, and the obvious fix for the cross-version marker bug -- ask the target interpreter over subprocess -- would have landed squarely on the portable path, on every run. So write it down where someone would reach for it: the module docstring, and _get_environment(), which is where the temptation is. The docstring also points at the file-based alternative: pyvenv.cfg carries "version = 3.13.7" for a venv, python313.dll at the root gives major.minor for a plain install or WinPython, and neither is needed unless target differs from the running interpreter. Comments only, no behaviour change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent d6e1bc8 commit be1b606

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

wppm/piptree.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
piptree.py: inspect and display Python package dependencies,
44
supporting both downward and upward dependency trees.
55
Requires Python 3.8+ due to importlib.metadata.
6+
7+
Keep this module free of subprocess: it must stay pure importlib.metadata +
8+
pathlib, so it can run where no process can be spawned -- notably inside
9+
JupyterLite/Pyodide, where piptree is known to work. The rest of wppm
10+
(Distribution, -md, -i, -u) does spawn and is Windows-only; piptree is the
11+
part that travels. See _get_environment() for the one place this bites.
612
"""
713

814
import json
@@ -58,7 +64,21 @@ def normalize(name: str) -> str:
5864
return re.sub(r"[-_.]+", "-", name).lower()
5965

6066
def _get_environment(self) -> Dict[str, str]:
61-
"""Collect system and Python environment details."""
67+
"""Collect system and Python environment details, for marker evaluation.
68+
69+
These describe the *running* interpreter, not `target`. So when -t points
70+
at another Python, markers can pick the wrong branch: a 3.13 target read
71+
from a 3.14 wppm resolves `python_version >= '3.14'` as true. pip_list()
72+
is unaffected (it evaluates no marker); down()/up() are.
73+
74+
Do NOT fix this by asking the target interpreter over subprocess: this
75+
runs once per PipData, on the only code path that works without process
76+
spawning (see module docstring). Read the target's version from files
77+
instead -- `pyvenv.cfg` carries `version = 3.13.7` for a venv, and
78+
`python313.dll` at the root gives major.minor for a plain install or
79+
WinPython (skip the `...t.dll` free-threaded variant). Both are ordinary
80+
reads, and only needed when target is not the running interpreter.
81+
"""
6282
return {
6383
"implementation_name": sys.implementation.name,
6484
"implementation_version": f"{sys.implementation.version.major}.{sys.implementation.version.minor}.{sys.implementation.version.micro}",

0 commit comments

Comments
 (0)