1414from typing import Any , Literal , overload
1515
1616import virtualenv as _virtualenv
17+ from filelock import FileLock
1718
1819if sys .version_info < (3 , 11 ):
1920 import tomli as tomllib
3738VIRTUALENV_VERSION = Version (metadata .version ("virtualenv" ))
3839
3940
40- def pytest_configure (config ) -> None :
41- if hasattr (config , "workerinput" ):
42- return # Running in pytest-xdist worker
43-
44- wheelhouse = config .cache .mkdir ("wheelhouse" )
45-
46- subprocess .run (
47- [
48- sys .executable ,
49- "-m" ,
50- "pip" ,
51- "wheel" ,
52- "--no-build-isolation" ,
53- "--wheel-dir" ,
54- str (wheelhouse ),
55- f"{ BASE } " ,
56- ],
57- check = True ,
58- )
41+ @pytest .fixture (scope = "session" )
42+ def pep518_wheelhouse (pytestconfig : pytest .Config ) -> Path :
43+ wheelhouse = pytestconfig .cache .mkdir ("wheelhouse" )
44+
45+ main_lock = FileLock (wheelhouse / "main.lock" )
46+ with main_lock :
47+ subprocess .run (
48+ [
49+ sys .executable ,
50+ "-m" ,
51+ "pip" ,
52+ "wheel" ,
53+ "--wheel-dir" ,
54+ str (wheelhouse ),
55+ "--no-build-isolation" ,
56+ f"{ BASE } " ,
57+ ],
58+ check = True ,
59+ capture_output = True ,
60+ text = True ,
61+ )
5962
60- if not all (list (wheelhouse .glob (f"{ p } *.whl" )) for p in download_wheels .WHEELS ):
61- download_wheels .prepare (wheelhouse )
63+ wheels_lock = FileLock (wheelhouse / "wheels.lock" )
64+ with wheels_lock :
65+ if not all (list (wheelhouse .glob (f"{ p } *.whl" )) for p in download_wheels .WHEELS ):
66+ download_wheels .prepare (wheelhouse )
67+
68+ return wheelhouse
6269
6370
6471class VEnv :
@@ -152,10 +159,9 @@ def prepare_no_build_isolation(self) -> None:
152159
153160
154161@pytest .fixture
155- def isolated (tmp_path : Path , pytestconfig : pytest . Config ) -> VEnv :
162+ def isolated (tmp_path : Path , pep518_wheelhouse : Path ) -> VEnv :
156163 path = tmp_path / "venv"
157- wheelhouse = pytestconfig .cache .mkdir ("wheelhouse" ).resolve ()
158- return VEnv (path , wheelhouse = wheelhouse )
164+ return VEnv (path , wheelhouse = pep518_wheelhouse )
159165
160166
161167@pytest .fixture
@@ -345,7 +351,7 @@ def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
345351 item .add_marker (pytest .mark .network )
346352
347353
348- def pytest_report_header (config : pytest . Config ) -> str :
354+ def pytest_report_header () -> str :
349355 with BASE .joinpath ("pyproject.toml" ).open ("rb" ) as f :
350356 pyproject = tomllib .load (f )
351357 project = pyproject .get ("project" , {})
@@ -357,9 +363,6 @@ def pytest_report_header(config: pytest.Config) -> str:
357363 interesting_packages = {Requirement (p ).name for p in pkgs }
358364 interesting_packages .add ("pip" )
359365
360- wheelhouse = config .cache .mkdir ("wheelhouse" )
361- pkgs = wheelhouse .glob ("*.whl" )
362-
363366 valid = []
364367 for package in sorted (interesting_packages ):
365368 with contextlib .suppress (ModuleNotFoundError ):
@@ -368,6 +371,5 @@ def pytest_report_header(config: pytest.Config) -> str:
368371 lines = [
369372 f"installed packages of interest: { reqs } " ,
370373 f"sysconfig platform: { sysconfig .get_platform ()} " ,
371- f"wheelhouse: { ' ' .join ('-' .join (p .name .split ('-' )[:2 ]) for p in pkgs )} " ,
372374 ]
373375 return "\n " .join (lines )
0 commit comments