-
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression in venv symlinking. (#2090)
The change in #2033 that safeguarded loose `--venv` PEXes such that they could be executed, moved and continue to execute properly from their new location, silently broke zipapp and packed layout `--venv` PEX symlinking. Although `--venv` PEXes for those layouts continued to work, they used copying to build their venvs instead of symlinking even when symlinking (the default for `--venv` PEXes) was the intended style. Fixes #2088
- Loading branch information
Showing
4 changed files
with
135 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
import os.path | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
import pytest | ||
|
||
from pex.common import safe_rmtree | ||
from pex.compatibility import commonpath | ||
from pex.layout import Layout | ||
from pex.testing import run_pex_command | ||
from pex.typing import TYPE_CHECKING | ||
from pex.venv.virtualenv import Virtualenv | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"layout", [pytest.param(layout, id=layout.value) for layout in Layout.values()] | ||
) | ||
@pytest.mark.parametrize( | ||
"symlink_site_packages", | ||
[ | ||
pytest.param(True, id="--no-venv-site-packages-copies"), | ||
pytest.param(False, id="--venv-site-packages-copies"), | ||
], | ||
) | ||
def test_venv_symlink_site_packages( | ||
tmpdir, # type: Any | ||
layout, # type: Layout.Value | ||
symlink_site_packages, # type: bool | ||
): | ||
# type: (...) -> None | ||
|
||
pex = os.path.join(str(tmpdir), "pex") | ||
pex_root = os.path.join(str(tmpdir), "pex_root") | ||
venv_site_packages_copies_arg = ( | ||
"--no-venv-site-packages-copies" if symlink_site_packages else "--venv-site-packages-copies" | ||
) | ||
result = run_pex_command( | ||
args=[ | ||
"ansicolors==1.1.8", | ||
"--pex-root", | ||
pex_root, | ||
"--runtime-pex-root", | ||
pex_root, | ||
"--venv", | ||
venv_site_packages_copies_arg, | ||
"--layout", | ||
layout.value, | ||
"--seed", | ||
"-o", | ||
pex, | ||
] | ||
) | ||
result.assert_success() | ||
venv_pex_path = str(result.output.strip()) | ||
|
||
safe_rmtree(pex_root) | ||
colors_module_realpath = os.path.realpath( | ||
subprocess.check_output( | ||
args=[sys.executable, pex, "-c", "import colors; print(colors.__file__)"] | ||
) | ||
.decode("utf-8") | ||
.strip() | ||
) | ||
|
||
venv_dir = os.path.dirname(venv_pex_path) | ||
virtualenv = Virtualenv(venv_dir) | ||
site_packages_dir = os.path.realpath(virtualenv.site_packages_dir) | ||
|
||
ansicolors_venv_package_dir_realpath = os.path.join(site_packages_dir, "colors") | ||
assert os.path.isdir(ansicolors_venv_package_dir_realpath) | ||
|
||
symlinks_expected = symlink_site_packages and layout != Layout.LOOSE | ||
assert os.path.islink(ansicolors_venv_package_dir_realpath) == symlinks_expected | ||
|
||
if symlinks_expected: | ||
installed_wheels_dir_realpath = os.path.realpath(os.path.join(pex_root, "installed_wheels")) | ||
assert installed_wheels_dir_realpath == commonpath( | ||
(installed_wheels_dir_realpath, colors_module_realpath) | ||
) | ||
else: | ||
assert ( | ||
os.path.join(ansicolors_venv_package_dir_realpath, "__init__.py") | ||
== colors_module_realpath | ||
) |