Skip to content

Commit 150798d

Browse files
authored
Fix setuptools_wheel fixture (pypa#4308)
2 parents cb5048f + 14ce350 commit 150798d

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

newsfragments/4308.misc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``setuptools_wheel`` fixture and avoid the recursive creation of
2+
``build/lib/build/lib/build/...`` directories in the project root during tests.

setuptools/tests/fixtures.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,46 @@ def sample_project(tmp_path):
6363
# sdist and wheel artifacts should be stable across a round of tests
6464
# so we can build them once per session and use the files as "readonly"
6565

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.
6669

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()
7270

71+
def _build_distributions(tmp_path_factory, request):
7372
with contexts.session_locked_tmp_dir(
74-
request, tmp_path_factory, "sdist_build"
73+
request, tmp_path_factory, "dist_build"
7574
) 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()
7982

8083
subprocess.check_output([
8184
sys.executable,
8285
"-m",
8386
"build",
84-
"--sdist",
8587
"--outdir",
8688
str(tmp),
8789
str(request.config.rootdir),
8890
])
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
90106

91107

92108
@pytest.fixture(scope="session")
@@ -95,23 +111,8 @@ def setuptools_wheel(tmp_path_factory, request):
95111
if prebuilt and os.path.exists(prebuilt): # pragma: no cover
96112
return Path(prebuilt).resolve()
97113

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
115116

116117

117118
@pytest.fixture

0 commit comments

Comments
 (0)