Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for missing pyvenv.cfg with virtualenvs.create=false #8672

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/poetry/utils/env/virtual_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _updated_path(self) -> str:
@cached_property
def includes_system_site_packages(self) -> bool:
pyvenv_cfg = self._path / "pyvenv.cfg"
return (
return pyvenv_cfg.exists() and (
re.search(
r"^\s*include-system-site-packages\s*=\s*true\s*$",
pyvenv_cfg.read_text(),
Expand Down
34 changes: 27 additions & 7 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,30 +1373,50 @@ def test_venv_has_correct_paths(tmp_venv: VirtualEnv) -> None:
)


def test_env_system_packages(tmp_path: Path, poetry: Poetry) -> None:
@pytest.mark.parametrize("with_system_site_packages", [True, False])
def test_env_system_packages(
tmp_path: Path, poetry: Poetry, with_system_site_packages: bool
) -> None:
venv_path = tmp_path / "venv"
pyvenv_cfg = venv_path / "pyvenv.cfg"

EnvManager(poetry).build_venv(path=venv_path, flags={"system-site-packages": True})
EnvManager(poetry).build_venv(
path=venv_path, flags={"system-site-packages": with_system_site_packages}
)
env = VirtualEnv(venv_path)

assert "include-system-site-packages = true" in pyvenv_cfg.read_text()
assert env.includes_system_site_packages
assert (
f"include-system-site-packages = {str(with_system_site_packages).lower()}"
in pyvenv_cfg.read_text()
)
assert env.includes_system_site_packages is with_system_site_packages


def test_generic_env_system_packages(poetry: Poetry) -> None:
"""https://github.com/python-poetry/poetry/issues/8646"""
env = GenericEnv(Path(sys.base_prefix))
assert not env.includes_system_site_packages


@pytest.mark.parametrize("with_system_site_packages", [True, False])
def test_env_system_packages_are_relative_to_lib(
tmp_path: Path, poetry: Poetry
tmp_path: Path, poetry: Poetry, with_system_site_packages: bool
) -> None:
venv_path = tmp_path / "venv"
EnvManager(poetry).build_venv(path=venv_path, flags={"system-site-packages": True})
EnvManager(poetry).build_venv(
path=venv_path, flags={"system-site-packages": with_system_site_packages}
)
env = VirtualEnv(venv_path)
site_dir = Path(site.getsitepackages()[-1])
for dist in metadata.distributions():
# Emulate is_relative_to, only available in 3.9+
with contextlib.suppress(ValueError):
dist._path.relative_to(site_dir) # type: ignore[attr-defined]
break
assert env.is_path_relative_to_lib(dist._path) # type: ignore[attr-defined]
assert (
env.is_path_relative_to_lib(dist._path) # type: ignore[attr-defined]
is with_system_site_packages
)


@pytest.mark.parametrize(
Expand Down
Loading