Skip to content

Commit f1ecea0

Browse files
committed
Avoid setuptools_wheel fixture to create recursively nested build/lib/build/lib/... directories
Based on the test introduced in b4d3e83, we can see that when none of `PRE_BUILT_SETUPTOOLS_SDIST` or `PRE_BUILT_SETUPTOOLS_WHEEL` is set, the `setuptools_wheel` fixture keeps recursively creating `build/lib/build/lib/...` directories which slows down the tests and creates a huge amount of unnecessary files. This change tries to target that.
1 parent 8837459 commit f1ecea0

File tree

1 file changed

+23
-40
lines changed

1 file changed

+23
-40
lines changed

setuptools/tests/fixtures.py

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,73 +63,56 @@ 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)
7979

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/...
8281
assert not Path(request.config.rootdir, "build/lib/build").exists()
8382

8483
subprocess.check_output([
8584
sys.executable,
8685
"-m",
8786
"build",
88-
"--sdist",
8987
"--outdir",
9088
str(tmp),
9189
str(request.config.rootdir),
9290
])
9391

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/...
9693
assert not Path(request.config.rootdir, "build/lib/build").exists()
9794

98-
return next(tmp.glob("*.tar.gz"))
95+
return next(tmp.glob("*.tar.gz")), next(tmp.glob("*.whl"))
9996

10097

10198
@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")
104101
if prebuilt and os.path.exists(prebuilt): # pragma: no cover
105102
return Path(prebuilt).resolve()
106103

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
113106

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

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

132-
return next(tmp.glob("*.whl"))
114+
_, wheel = _build_distributions(tmp_path_factory, request)
115+
return wheel
133116

134117

135118
@pytest.fixture

0 commit comments

Comments
 (0)