Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alow backend build system to omit get_requires_for_build_sdist hook #2131

Merged
merged 5 commits into from Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
69 changes: 69 additions & 0 deletions tests/unit/package/builder/test_package_builder_isolated.py
Expand Up @@ -202,3 +202,72 @@ 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 with enscons as backend
jugmac00 marked this conversation as resolved.
Show resolved Hide resolved
"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