fix: isolate script mode from inherited PYTHONPATH - #1157
Merged
henryiii merged 3 commits intoAug 10, 2026
Conversation
yangfan-yf-yf
marked this pull request as ready for review
August 9, 2026 11:05
The strip protects the installer and the re-exec'd Nox interpreter, but sessions must see the same environment as a NOX_SCRIPT_MODE=none run. Stash the value as NOX_OUTER_PYTHONPATH and restore it in the child. Assisted-by: ClaudeCode:claude-fable-5
A mismatched outer PYTHONHOME is fatal to any venv interpreter (Fatal Python error: Failed to import encodings module), and venv activate scripts unset it for the same reason. Assisted-by: ClaudeCode:claude-fable-5
henryiii
force-pushed
the
fix-1044-script-mode-pythonpath
branch
from
August 10, 2026 15:54
129fd5d to
3125a02
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1044.
Problem
I reproduced the failure by placing a second Nox distribution on the outer
PYTHONPATHand forcing a freshvirtualenvscript environment.run_script_mode()carried that path into both the dependency installer and the re-executed Nox process. Pip could therefore treat the outer Nox distribution as already installed, while the child process could resolve packages outside the script environment instead of using the dependencies installed there.Change
I remove
PYTHONPATHfrom the environment passed to the installer and the re-executed Nox process when the selected backend is sandboxed.The
nonebackend continues to inheritPYTHONPATH, preserving its existing non-isolated behavior.I also added:
nonebackends across both process handoffs;virtualenvscript environment.Tests
pytest tests/test__cli.py::test_run_script_mode_pythonpath_isolation tests/test_main.py::test_noxfile_script_mode— 3 passedpytest tests/test_main.py::test_noxfile_script_mode_url_req— 1 passedgit diff --checkpassed