🐛 fix(env): strip PYTHONPATH from isolated builds#1024
Conversation
6301f3b to
10ceaa3
Compare
When PYTHONPATH is set in the host environment it leaks into isolated build subprocesses, causing the build backend and package installers to discover packages from the host instead of the isolated venv. This breaks the isolation contract and can cause build failures when the host has incompatible package versions. Strip PYTHONPATH from os.environ on DefaultIsolatedEnv entry and restore it on exit. This covers all subprocess calls within the isolated context: backend hook invocations via pyproject_hooks, pip and uv install commands, and venv creation via ensurepip.
10ceaa3 to
c6249bf
Compare
|
Updated the approach per your feedback. The fix now:
No |
|
Okay, that's reasonable. Maybe could be a future thing to do in pyproject_hooks. |
Closes #405
When
PYTHONPATHis set in the host environment, it leaks into isolated build subprocesses. The build backend and package installers then discover packages from the host instead of the isolated venv, breaking the isolation contract. 🔒 This causes hard-to-diagnose build failures when the host has incompatible package versions — for example, an old pip that lacks--use-pep517.The fix clears
PYTHONPATHinmake_extra_environ()so all backend hook calls via pyproject_hooks strip it from their subprocess environment. The uv backend's install path, which explicitly passesos.environ, also gets the same treatment. Internal pip calls already use-Im(isolated mode) which ignoresPYTHONPATH, so they were unaffected.Setting
PYTHONPATHto an empty string (rather than removing it) ensures the key is present in the environment dict and overrides whatever value the host had, even when the runner merges it withos.environ.copy(). Non-isolated builds (--no-isolation) are unaffected since they don't go throughDefaultIsolatedEnv.