@@ -63,30 +63,46 @@ def sample_project(tmp_path):
63
63
# sdist and wheel artifacts should be stable across a round of tests
64
64
# so we can build them once per session and use the files as "readonly"
65
65
66
+ # In the case of setuptools, building the wheel without sdist may cause
67
+ # it to contain the `build` directory, and therefore create situations with
68
+ # `setuptools/build/lib/build/lib/...`. To avoid that, build both artifacts at once.
66
69
67
- @pytest .fixture (scope = "session" )
68
- def setuptools_sdist (tmp_path_factory , request ):
69
- prebuilt = os .getenv ("PRE_BUILT_SETUPTOOLS_SDIST" )
70
- if prebuilt and os .path .exists (prebuilt ): # pragma: no cover
71
- return Path (prebuilt ).resolve ()
72
70
71
+ def _build_distributions (tmp_path_factory , request ):
73
72
with contexts .session_locked_tmp_dir (
74
- request , tmp_path_factory , "sdist_build "
73
+ request , tmp_path_factory , "dist_build "
75
74
) as tmp : # pragma: no cover
76
- dist = next (tmp .glob ("*.tar.gz" ), None )
77
- if dist :
78
- return dist
75
+ sdist = next (tmp .glob ("*.tar.gz" ), None )
76
+ wheel = next (tmp .glob ("*.whl" ), None )
77
+ if sdist and wheel :
78
+ return (sdist , wheel )
79
+
80
+ # Sanity check: should not create recursive setuptools/build/lib/build/lib/...
81
+ assert not Path (request .config .rootdir , "build/lib/build" ).exists ()
79
82
80
83
subprocess .check_output ([
81
84
sys .executable ,
82
85
"-m" ,
83
86
"build" ,
84
- "--sdist" ,
85
87
"--outdir" ,
86
88
str (tmp ),
87
89
str (request .config .rootdir ),
88
90
])
89
- return next (tmp .glob ("*.tar.gz" ))
91
+
92
+ # Sanity check: should not create recursive setuptools/build/lib/build/lib/...
93
+ assert not Path (request .config .rootdir , "build/lib/build" ).exists ()
94
+
95
+ return next (tmp .glob ("*.tar.gz" )), next (tmp .glob ("*.whl" ))
96
+
97
+
98
+ @pytest .fixture (scope = "session" )
99
+ def setuptools_sdist (tmp_path_factory , request ):
100
+ prebuilt = os .getenv ("PRE_BUILT_SETUPTOOLS_SDIST" )
101
+ if prebuilt and os .path .exists (prebuilt ): # pragma: no cover
102
+ return Path (prebuilt ).resolve ()
103
+
104
+ sdist , _ = _build_distributions (tmp_path_factory , request )
105
+ return sdist
90
106
91
107
92
108
@pytest .fixture (scope = "session" )
@@ -95,23 +111,8 @@ def setuptools_wheel(tmp_path_factory, request):
95
111
if prebuilt and os .path .exists (prebuilt ): # pragma: no cover
96
112
return Path (prebuilt ).resolve ()
97
113
98
- with contexts .session_locked_tmp_dir (
99
- request , tmp_path_factory , "wheel_build"
100
- ) as tmp : # pragma: no cover
101
- dist = next (tmp .glob ("*.whl" ), None )
102
- if dist :
103
- return dist
104
-
105
- subprocess .check_output ([
106
- sys .executable ,
107
- "-m" ,
108
- "build" ,
109
- "--wheel" ,
110
- "--outdir" ,
111
- str (tmp ),
112
- str (request .config .rootdir ),
113
- ])
114
- return next (tmp .glob ("*.whl" ))
114
+ _ , wheel = _build_distributions (tmp_path_factory , request )
115
+ return wheel
115
116
116
117
117
118
@pytest .fixture
0 commit comments