Skip to content

Commit

Permalink
Alow backend build system to omit get_requires_for_build_sdist hook (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
oczkoisse committed Jul 31, 2021
1 parent a61a6b6 commit db5861c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -99,6 +99,7 @@ Philip Thiem
Pierre-Jean Campigotto
Pierre-Luc Tessier Gagné
Prakhar Gurunani
Rahul Bangar
Ronald Evers
Ronny Pfannschmidt
Ryuichi Ohori
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/2130.bugfix.rst
@@ -0,0 +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`
9 changes: 8 additions & 1 deletion src/tox/helper/build_requires.py
Expand Up @@ -12,6 +12,13 @@
if backend_obj:
backend = getattr(backend, backend_obj)

for_build_requires = backend.get_requires_for_build_sdist(None)
try:
for_build_requires = backend.get_requires_for_build_sdist(None)
except AttributeError:
# PEP 517 states that get_requires_for_build_sdist is optional for a build
# backend object. When the backend object omits it, the default
# implementation must be equivalent to return []
for_build_requires = []

output = json.dumps(for_build_requires)
print(output)
68 changes: 68 additions & 0 deletions tests/unit/package/builder/test_package_builder_isolated.py
Expand Up @@ -202,3 +202,71 @@ def test_isolated_build_script_args(tmp_path):
# cannot import build_isolated because of its side effects
script_path = os.path.join(os.path.dirname(tox.helper.__file__), "build_isolated.py")
subprocess.check_call(("python", script_path, str(tmp_path), "setuptools.build_meta"))


def test_isolated_build_backend_missing_hook(initproj, cmd):
"""Verify that tox works with a backend missing optional hooks
PEP 517 allows backends to omit get_requires_for_build_sdist hook, in which
case a default implementation that returns an empty list should be assumed
instead of raising an error.
"""
name = "ensconsproj"
version = "0.1"
src_root = "src"

initproj(
(name, version),
filedefs={
"pyproject.toml": """
[build-system]
requires = ["pytoml>=0.1", "enscons==0.26.0"]
build-backend = "enscons.api"
[tool.enscons]
name = "{name}"
version = "{version}"
description = "Example enscons project"
license = "MIT"
packages = ["{name}"]
src_root = "{src_root}"
""".format(
name=name, version=version, src_root=src_root
),
"tox.ini": """
[tox]
isolated_build = true
""",
"SConstruct": """
import enscons
env = Environment(
tools=["default", "packaging", enscons.generate],
PACKAGE_METADATA=dict(
name = "{name}",
version = "{version}"
),
WHEEL_TAG="py2.py3-none-any"
)
py_source = env.Glob("src/{name}/*.py")
purelib = env.Whl("purelib", py_source, root="{src_root}")
whl = env.WhlFile(purelib)
sdist = env.SDist(source=FindSourceFiles() + ["PKG-INFO"])
env.NoClean(sdist)
env.Alias("sdist", sdist)
develop = env.Command("#DEVELOP", enscons.egg_info_targets(env), enscons.develop)
env.Alias("develop", develop)
env.Default(whl, sdist)
""".format(
name=name, version=version, src_root=src_root
),
},
)

result = cmd("--sdistonly", "-v", "-v", "-e", "py")
assert "scons: done building targets" in result.out, result.out

0 comments on commit db5861c

Please sign in to comment.