From 7d1bcacffba2e569e485abe2d0b863bbe1830904 Mon Sep 17 00:00:00 2001 From: Nicolas Vivet Date: Wed, 19 Aug 2020 14:38:36 +0200 Subject: [PATCH 1/2] Fix support of the PEP517 backend-path key --- src/tox/helper/build_requires.py | 4 ++ src/tox/package/builder/isolated.py | 10 +++++ .../builder/test_package_builder_isolated.py | 40 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/src/tox/helper/build_requires.py b/src/tox/helper/build_requires.py index cd074f97f..aafb258cb 100644 --- a/src/tox/helper/build_requires.py +++ b/src/tox/helper/build_requires.py @@ -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: diff --git a/src/tox/package/builder/isolated.py b/src/tox/package/builder/isolated.py index 38ebe8ea5..998ce25fb 100644 --- a/src/tox/package/builder/isolated.py +++ b/src/tox/package/builder/isolated.py @@ -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) @@ -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, diff --git a/tests/unit/package/builder/test_package_builder_isolated.py b/tests/unit/package/builder/test_package_builder_isolated.py index 63e0685a8..458e43bbe 100644 --- a/tests/unit/package/builder/test_package_builder_isolated.py +++ b/tests/unit/package/builder/test_package_builder_isolated.py @@ -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 From a8f7c6045977c153f8837dd4e31df550725c5fff Mon Sep 17 00:00:00 2001 From: Nicolas Vivet Date: Wed, 19 Aug 2020 16:47:01 +0200 Subject: [PATCH 2/2] Add changelog entry --- CONTRIBUTORS | 1 + docs/changelog/1654.bugfix.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 docs/changelog/1654.bugfix.rst diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 8eac46c94..1c57f6599 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -78,6 +78,7 @@ Morgan Fainberg Naveen S R Nick Douma Nick Prendergast +Nicolas Vivet Oliver Bestwalter Pablo Galindo Paul Moore diff --git a/docs/changelog/1654.bugfix.rst b/docs/changelog/1654.bugfix.rst new file mode 100644 index 000000000..0d20d48af --- /dev/null +++ b/docs/changelog/1654.bugfix.rst @@ -0,0 +1 @@ +Support for PEP517 in-tree build backend-path key in ``get-build-requires``. - by :user:`nizox`