Skip to content

🐛 fix(create): preserve reported sys.path in safe-path mode - #3589

Merged
gaborbernat merged 2 commits into
pypa:mainfrom
Pratik-Kumar-Dhakar:fix/debug-safe-path
Nov 20, 2026
Merged

gaborbernat merged 2 commits into
pypa:mainfrom
Pratik-Kumar-Dhakar:fix/debug-safe-path

Conversation

@Pratik-Kumar-Dhakar

@Pratik-Kumar-Dhakar Pratik-Kumar-Dhakar commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

With PYTHONSAFEPATH enabled, virtualenv's target debug report omits the first real sys.path entry, so -vv output and Creator.debug can misrepresent the environment (#3584). This change restores the complete reported path; the created environment is unchanged.

Safe-path mode omits the script directory. The debug runner's child process collects the target report, and its path cleanup then removes the first entry as the script directory. The runner now clears PYTHONSAFEPATH from that child process, matching its treatment of PYTHONPATH, so the cleanup removes the debug script directory instead of an environment path entry.

Contributor checklist

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added a docs/changelog/+short-description.<type>.rst fragment for each user-facing change, or applied skip news
  • updated/extended the documentation
  • for changes to activation scripts, pyvenv.cfg, wheel downloads, app-data or release workflows: explained in the PR text which outside input the change handles (not applicable)
  • ran tests on Python 3.9 and 3.15 (the affected test modules, with pytest in 3.9 and 3.15 environments rather than through tox. On 3.9, one fixture-teardown error also happens on main in my environment)
  • linked upstream issues beside any temporary interpreter overrides

See the development documentation for checklist details.

@Pratik-Kumar-Dhakar
Pratik-Kumar-Dhakar marked this pull request as ready for review November 19, 2026 16:58
Pratik-Kumar-Dhakar and others added 2 commits November 19, 2026 17:11
The debug script runs without its directory on sys.path when
PYTHONSAFEPATH is set. The report then discards the first real path entry.
Clear that setting for the probe, as already done for PYTHONPATH.

Fixes pypa#3584
@gaborbernat gaborbernat changed the title 🐛 fix(create): keep sys.path intact in the debug report under PYTHONSAFEPATH 🐛 fix(create): preserve reported sys.path in safe-path mode Nov 20, 2026
@gaborbernat
gaborbernat merged commit a12baf7 into pypa:main Nov 20, 2026
82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants