pypa / virtualenv

Virtual Python Environment builder
https://virtualenv.pypa.io
MIT License
4.78k stars 1.02k forks source link

Fix #1949: zipapp virtual environment creation fails if zipapp path is symlinked #2722

Closed HandSonic closed 3 months ago

HandSonic commented 3 months ago

Original issue: https://github.com/pypa/virtualenv/issues/1949

Added test for pull https://github.com/pypa/virtualenv/pull/2613

The function in question assumes that ROOT is a prefix of full_path, and tries to remove it. However, it is not necessarily a prefix:

  • when ROOT is determined, both os.path.abspath() and os.path.realpath() gets called
  • when full_path is determined, only os.path.abspath() is called

This means that if the path contains a symlink, it will show up as resolved in ROOT, but not full_path, so simply removing the first X characters of full_path is not sufficient.

This PR adds an assertion to catch the bad situation early, then adds the os.path.realpath call to full_path.

  • [x] ran the linter to address style issues (tox -e fix)
  • [x] wrote descriptive pull request text
  • [x] ensured there are test(s) validating the fix
  • [x] added news fragment in docs/changelog folder
  • [x] updated/extended the documentation