Skip to content

fix: isolate script mode from inherited PYTHONPATH - #1157

Merged
henryiii merged 3 commits into
wntrblm:mainfrom
yangfan-yf-yf:fix-1044-script-mode-pythonpath
Aug 10, 2026
Merged

fix: isolate script mode from inherited PYTHONPATH#1157
henryiii merged 3 commits into
wntrblm:mainfrom
yangfan-yf-yf:fix-1044-script-mode-pythonpath

Conversation

@yangfan-yf-yf

Copy link
Copy Markdown
Contributor

Fixes #1044.

Problem

I reproduced the failure by placing a second Nox distribution on the outer PYTHONPATH and forcing a fresh virtualenv script 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 PYTHONPATH from the environment passed to the installer and the re-executed Nox process when the selected backend is sandboxed.

The none backend continues to inherit PYTHONPATH, preserving its existing non-isolated behavior.

I also added:

  • a parameterized regression test covering sandboxed and none backends across both process handoffs;
  • an end-to-end regression that exposes an outer Nox distribution and forces a fresh virtualenv script environment.

Tests

  • pytest tests/test__cli.py::test_run_script_mode_pythonpath_isolation tests/test_main.py::test_noxfile_script_mode — 3 passed
  • pytest tests/test_main.py::test_noxfile_script_mode_url_req — 1 passed
  • Ruff lint and format checks passed
  • Mypy passed
  • codespell passed
  • git diff --check passed

@yangfan-yf-yf
yangfan-yf-yf marked this pull request as ready for review August 9, 2026 11:05
yangfan-yf-yf and others added 3 commits August 10, 2026 11:54
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
henryiii force-pushed the fix-1044-script-mode-pythonpath branch from 129fd5d to 3125a02 Compare August 10, 2026 15:54
@henryiii
henryiii merged commit c7134d4 into wntrblm:main Aug 10, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Some nox tests fails when PYTHONPATH is set

2 participants