Skip to content

Commit db5861c

Browse files
authored
Alow backend build system to omit get_requires_for_build_sdist hook (#2131)
* Fix isolated build with backends missing optional hooks * Add a test for verifying that tox works with enscons * Remove a redundant comment * Add name to CONTRIBUTORS * Add changelog entry
1 parent a61a6b6 commit db5861c

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Philip Thiem
9999
Pierre-Jean Campigotto
100100
Pierre-Luc Tessier Gagné
101101
Prakhar Gurunani
102+
Rahul Bangar
102103
Ronald Evers
103104
Ronny Pfannschmidt
104105
Ryuichi Ohori

docs/changelog/2130.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``get_requires_for_build_sdist`` hook (PEP 517) is assumed to return an empty list if left unimplemented by the backend build system - by :user:`oczkoisse`

src/tox/helper/build_requires.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
if backend_obj:
1313
backend = getattr(backend, backend_obj)
1414

15-
for_build_requires = backend.get_requires_for_build_sdist(None)
15+
try:
16+
for_build_requires = backend.get_requires_for_build_sdist(None)
17+
except AttributeError:
18+
# PEP 517 states that get_requires_for_build_sdist is optional for a build
19+
# backend object. When the backend object omits it, the default
20+
# implementation must be equivalent to return []
21+
for_build_requires = []
22+
1623
output = json.dumps(for_build_requires)
1724
print(output)

tests/unit/package/builder/test_package_builder_isolated.py

+68
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,71 @@ def test_isolated_build_script_args(tmp_path):
202202
# cannot import build_isolated because of its side effects
203203
script_path = os.path.join(os.path.dirname(tox.helper.__file__), "build_isolated.py")
204204
subprocess.check_call(("python", script_path, str(tmp_path), "setuptools.build_meta"))
205+
206+
207+
def test_isolated_build_backend_missing_hook(initproj, cmd):
208+
"""Verify that tox works with a backend missing optional hooks
209+
210+
PEP 517 allows backends to omit get_requires_for_build_sdist hook, in which
211+
case a default implementation that returns an empty list should be assumed
212+
instead of raising an error.
213+
"""
214+
name = "ensconsproj"
215+
version = "0.1"
216+
src_root = "src"
217+
218+
initproj(
219+
(name, version),
220+
filedefs={
221+
"pyproject.toml": """
222+
[build-system]
223+
requires = ["pytoml>=0.1", "enscons==0.26.0"]
224+
build-backend = "enscons.api"
225+
226+
[tool.enscons]
227+
name = "{name}"
228+
version = "{version}"
229+
description = "Example enscons project"
230+
license = "MIT"
231+
packages = ["{name}"]
232+
src_root = "{src_root}"
233+
""".format(
234+
name=name, version=version, src_root=src_root
235+
),
236+
"tox.ini": """
237+
[tox]
238+
isolated_build = true
239+
""",
240+
"SConstruct": """
241+
import enscons
242+
243+
env = Environment(
244+
tools=["default", "packaging", enscons.generate],
245+
PACKAGE_METADATA=dict(
246+
name = "{name}",
247+
version = "{version}"
248+
),
249+
WHEEL_TAG="py2.py3-none-any"
250+
)
251+
252+
py_source = env.Glob("src/{name}/*.py")
253+
254+
purelib = env.Whl("purelib", py_source, root="{src_root}")
255+
whl = env.WhlFile(purelib)
256+
257+
sdist = env.SDist(source=FindSourceFiles() + ["PKG-INFO"])
258+
env.NoClean(sdist)
259+
env.Alias("sdist", sdist)
260+
261+
develop = env.Command("#DEVELOP", enscons.egg_info_targets(env), enscons.develop)
262+
env.Alias("develop", develop)
263+
264+
env.Default(whl, sdist)
265+
""".format(
266+
name=name, version=version, src_root=src_root
267+
),
268+
},
269+
)
270+
271+
result = cmd("--sdistonly", "-v", "-v", "-e", "py")
272+
assert "scons: done building targets" in result.out, result.out

0 commit comments

Comments
 (0)