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 #2720

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
HandSonic commented 3 months ago

CI failing.

I checked ci. i think the reason ci fails is because the branch main ci fails before this pull. the branch main ci failure starts at https://github.com/pypa/virtualenv/pull/2716. When I do ci at https://github.com/pypa/virtualenv/pull/2714, it will pass. https://github.com/HandSonic/virtualenv/actions/runs/9039792423

gaborbernat commented 3 months ago

Be that so, however the only way I'll be able to merge this pull request is if the CI is green. Furthermore I will not have time anytime soon to work on this myself, so if you want to land this change set you will need to fix the CI either part of this request or a new one before we can land this one.