Skip to content

Commit

Permalink
Cache the includes_system_site_packages property
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Aug 25, 2023
1 parent 40bd409 commit 3c1b911
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/poetry/utils/env/virtual_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from contextlib import contextmanager
from copy import deepcopy
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
Expand Down Expand Up @@ -136,12 +137,13 @@ def temp_environ(self) -> Iterator[None]:
def _updated_path(self) -> str:
return os.pathsep.join([str(self._bin_dir), os.environ.get("PATH", "")])

@cached_property
def includes_system_site_packages(self) -> bool:
pyvenv_cfg = self._path / "pyvenv.cfg"
return "include-system-site-packages = true" in pyvenv_cfg.read_text()

def is_path_relative_to_lib(self, path: Path) -> bool:
return super().is_path_relative_to_lib(path) or (
self.includes_system_site_packages()
self.includes_system_site_packages
and SystemEnv(Path(sys.prefix)).is_path_relative_to_lib(path)
)
2 changes: 1 addition & 1 deletion tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ def test_env_system_packages(tmp_path: Path, poetry: Poetry) -> None:
env = VirtualEnv(venv_path)

assert "include-system-site-packages = true" in pyvenv_cfg.read_text()
assert env.includes_system_site_packages()
assert env.includes_system_site_packages


def test_env_system_packages_are_relative_to_lib(
Expand Down

0 comments on commit 3c1b911

Please sign in to comment.