File tree 3 files changed +18
-3
lines changed
3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -219,8 +219,11 @@ def platlib(self) -> Path:
219
219
220
220
return self ._platlib
221
221
222
+ def _get_lib_dirs (self ) -> list [Path ]:
223
+ return [self .purelib , self .platlib ]
224
+
222
225
def is_path_relative_to_lib (self , path : Path ) -> bool :
223
- for lib_path in [ self .purelib , self . platlib ] :
226
+ for lib_path in self ._get_lib_dirs () :
224
227
with contextlib .suppress (ValueError ):
225
228
path .relative_to (lib_path )
226
229
return True
Original file line number Diff line number Diff line change 2
2
3
3
import os
4
4
import platform
5
+ import site
5
6
import sys
6
7
import sysconfig
7
8
@@ -87,3 +88,6 @@ def get_pip_version(self) -> Version:
87
88
88
89
def is_venv (self ) -> bool :
89
90
return self ._path != self ._base
91
+
92
+ def _get_lib_dirs (self ) -> list [Path ]:
93
+ return super ()._get_lib_dirs () + [Path (d ) for d in site .getsitepackages ()]
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
+ import contextlib
3
4
import os
5
+ import site
4
6
import subprocess
5
7
import sys
6
8
@@ -1475,8 +1477,14 @@ def test_env_system_packages_are_relative_to_lib(
1475
1477
venv_path = tmp_path / "venv"
1476
1478
EnvManager (poetry ).build_venv (path = venv_path , flags = {"system-site-packages" : True })
1477
1479
env = VirtualEnv (venv_path )
1478
- pytest_dist = metadata .distribution ("pytest" )
1479
- assert env .is_path_relative_to_lib (pytest_dist ._path ) # type: ignore[attr-defined]
1480
+ site_dir = Path (site .getsitepackages ()[- 1 ])
1481
+ for p in metadata .distributions ():
1482
+ # Emulate is_relative_to, only available in 3.9+
1483
+ with contextlib .suppress (ValueError ):
1484
+ p ._path .relative_to (site_dir ) # type: ignore[attr-defined]
1485
+ dist = p
1486
+ break
1487
+ assert env .is_path_relative_to_lib (dist ._path ) # type: ignore[attr-defined]
1480
1488
1481
1489
1482
1490
@pytest .mark .parametrize (
You can’t perform that action at this time.
0 commit comments