Fix #1949: zipapp virtual environment creation fails if zipapp path is symlinked#2613
Fix #1949: zipapp virtual environment creation fails if zipapp path is symlinked#2613
Conversation
|
@gaborbernat I see the following possible solutions:
How do you want me to proceed? |
|
gaborbernat
left a comment
There was a problem hiding this comment.
Please add tests validating your change fixes the problem.
| full_path = os.path.realpath(os.path.abspath(str(full_path))) | ||
| prefix = ROOT + os.sep |
There was a problem hiding this comment.
Can we use here the pathlib variant instead?
There was a problem hiding this comment.
Sure. I saw most of the other code uses pathlib, but I wasn't sure whether it's intentional or not, and wanted to keep the size of the diff minimal. It's way simpler to implement the whole function using PurePath.relative_to anyway.
Question: if I migrate to pathlib, the trivial implementation will throw ValueError in case ROOT and full_path diverge, i.e. when my assert fails in the current version. Is that acceptable, or should I turn it back to an assert?
There was a problem hiding this comment.
The ValueError is fine considering we're not expecting it to happen.
Can you point me in the direction of where it should be added? I'm not that familiar with either pytest or tox. I also don't know how I could make sure the test passes because the issue is really fixed, or because of the caching behaviour described in the original report. Or should I add a unit test for the zipapp functionality specifically? Would the place for that be in |
|
You want to add it here https://github.com/pypa/virtualenv/blob/main/tests/integration/test_zipapp.py |
|
Seems stalled, closing until you pick it up again. |
|
Yeah, sorry, I'm swamped, and I'll be AFK next week. I hope to eventually get back to this and reopen... |
Original issue: #1949
The function in question assumes that
ROOTis a prefix offull_path, and tries to remove it. However, it is not necessarily a prefix:ROOTis determined, bothos.path.abspath()andos.path.realpath()gets calledfull_pathis determined, onlyos.path.abspath()is calledThis means that if the path contains a symlink, it will show up as resolved in
ROOT, but notfull_path, so simply removing the first X characters offull_pathis not sufficient.This PR adds an assertion to catch the bad situation early, then adds the
os.path.realpathcall tofull_path.I did not add a test because I was unable to figure out how to add it to the existing structure.
tox -e fix)docs/changelogfolder