Skip to content

Fix support of the PEP517 backend-path key #1655

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

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Morgan Fainberg
Naveen S R
Nick Douma
Nick Prendergast
Nicolas Vivet
Oliver Bestwalter
Pablo Galindo
Paul Moore
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/1654.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support for PEP517 in-tree build backend-path key in ``get-build-requires``. - by :user:`nizox`
4 changes: 4 additions & 0 deletions src/tox/helper/build_requires.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import json
import os
import sys

backend_spec = sys.argv[1]
backend_obj = sys.argv[2] if len(sys.argv) >= 3 else None
backend_paths = sys.argv[3].split(os.path.pathsep) if len(sys.argv) >= 4 else []

sys.path[:0] = backend_paths

backend = __import__(backend_spec, fromlist=["_trash"])
if backend_obj:
Expand Down
10 changes: 10 additions & 0 deletions src/tox/package/builder/isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ def abort(message):
abort("backend-path key at build-system section must be a list, if specified")
backend_paths = [folder.join(p) for p in backend_paths]

normalized_folder = os.path.normcase(str(folder.realpath()))
normalized_paths = (os.path.normcase(str(path.realpath())) for path in backend_paths)

if not all(
os.path.commonprefix((normalized_folder, path)) == normalized_folder
for path in normalized_paths
):
abort("backend-path must exist in the project root")

return BuildInfo(requires, module, obj, backend_paths)


Expand Down Expand Up @@ -129,6 +138,7 @@ def get_build_requires(build_info, package_venv, setup_dir):
BUILD_REQUIRE_SCRIPT,
build_info.backend_module,
build_info.backend_object,
os.path.pathsep.join(str(p) for p in build_info.backend_paths),
],
returnout=True,
action=action,
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/package/builder/test_package_builder_isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,43 @@ def test_package_isolated_toml_bad_backend_path(initproj):
backend-path = 42
""",
)


def test_package_isolated_toml_backend_path_outside_root(initproj):
"""Verify that a 'backend-path' outside the project root is forbidden."""
toml_file_check(
initproj,
6,
"backend-path must exist in the project root",
"""
[build-system]
requires = []
build-backend = 'setuptools.build_meta'
backend-path = ['..']
""",
)


def test_verbose_isolated_build_in_tree(initproj, mock_venv, cmd):
initproj(
"example123-0.5",
filedefs={
"tox.ini": """
[tox]
isolated_build = true
""",
"build.py": """
from setuptools.build_meta import *
""",
"pyproject.toml": """
[build-system]
requires = ["setuptools >= 35.0.2"]
build-backend = 'build'
backend-path = ['.']
""",
},
)
result = cmd("--sdistonly", "-v", "-v", "-v", "-e", "py")
assert "running sdist" in result.out, result.out
assert "running egg_info" in result.out, result.out
assert "Writing example123-0.5{}setup.cfg".format(os.sep) in result.out, result.out