diff --git a/docs/changelog/1949.bugfix.rst b/docs/changelog/1949.bugfix.rst new file mode 100644 index 000000000..adb7575f7 --- /dev/null +++ b/docs/changelog/1949.bugfix.rst @@ -0,0 +1 @@ +``virtualenv.pyz`` no longer fails when zipapp path contains a symlink - by :user:`petamas`. diff --git a/src/virtualenv/util/zipapp.py b/src/virtualenv/util/zipapp.py index 3049b8400..86464720a 100644 --- a/src/virtualenv/util/zipapp.py +++ b/src/virtualenv/util/zipapp.py @@ -23,8 +23,10 @@ def extract(full_path, dest): def _get_path_within_zip(full_path): - full_path = os.path.abspath(str(full_path)) - sub_file = full_path[len(ROOT) + 1 :] + full_path = os.path.realpath(os.path.abspath(str(full_path))) + prefix = ROOT + os.sep + assert full_path.startswith(prefix), f"full_path={full_path} should start with prefix={prefix}" + sub_file = full_path[len(prefix) :] if IS_WIN: # paths are always UNIX separators, even on Windows, though __file__ still follows platform default sub_file = sub_file.replace(os.sep, "/")