@@ -63,73 +63,56 @@ 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
79
80
- # Sanity check
81
- # Building should not create recursive `setuptools/build/lib/build/lib/...`
80
+ # Sanity check: should not create recursive setuptools/build/lib/build/lib/...
82
81
assert not Path (request .config .rootdir , "build/lib/build" ).exists ()
83
82
84
83
subprocess .check_output ([
85
84
sys .executable ,
86
85
"-m" ,
87
86
"build" ,
88
- "--sdist" ,
89
87
"--outdir" ,
90
88
str (tmp ),
91
89
str (request .config .rootdir ),
92
90
])
93
91
94
- # Sanity check
95
- # Building should not create recursive `setuptools/build/lib/build/lib/...`
92
+ # Sanity check: should not create recursive setuptools/build/lib/build/lib/...
96
93
assert not Path (request .config .rootdir , "build/lib/build" ).exists ()
97
94
98
- return next (tmp .glob ("*.tar.gz" ))
95
+ return next (tmp .glob ("*.tar.gz" )), next ( tmp . glob ( "*.whl" ))
99
96
100
97
101
98
@pytest .fixture (scope = "session" )
102
- def setuptools_wheel (tmp_path_factory , request ):
103
- prebuilt = os .getenv ("PRE_BUILT_SETUPTOOLS_WHEEL " )
99
+ def setuptools_sdist (tmp_path_factory , request ):
100
+ prebuilt = os .getenv ("PRE_BUILT_SETUPTOOLS_SDIST " )
104
101
if prebuilt and os .path .exists (prebuilt ): # pragma: no cover
105
102
return Path (prebuilt ).resolve ()
106
103
107
- with contexts .session_locked_tmp_dir (
108
- request , tmp_path_factory , "wheel_build"
109
- ) as tmp : # pragma: no cover
110
- dist = next (tmp .glob ("*.whl" ), None )
111
- if dist :
112
- return dist
104
+ sdist , _ = _build_distributions (tmp_path_factory , request )
105
+ return sdist
113
106
114
- # Sanity check
115
- # Building should not create recursive `setuptools/build/lib/build/lib/...`
116
- assert not Path (request .config .rootdir , "build/lib/build" ).exists ()
117
107
118
- subprocess .check_output ([
119
- sys .executable ,
120
- "-m" ,
121
- "build" ,
122
- "--wheel" ,
123
- "--outdir" ,
124
- str (tmp ),
125
- str (request .config .rootdir ),
126
- ])
127
-
128
- # Sanity check
129
- # Building should not create recursive `setuptools/build/lib/build/lib/...`
130
- assert not Path (request .config .rootdir , "build/lib/build" ).exists ()
108
+ @pytest .fixture (scope = "session" )
109
+ def setuptools_wheel (tmp_path_factory , request ):
110
+ prebuilt = os .getenv ("PRE_BUILT_SETUPTOOLS_WHEEL" )
111
+ if prebuilt and os .path .exists (prebuilt ): # pragma: no cover
112
+ return Path (prebuilt ).resolve ()
131
113
132
- return next (tmp .glob ("*.whl" ))
114
+ _ , wheel = _build_distributions (tmp_path_factory , request )
115
+ return wheel
133
116
134
117
135
118
@pytest .fixture
0 commit comments