From f6e60fd51103cae1e5d71f1ed102d2238beaf0fa Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Tue, 28 Jul 2020 09:16:43 +0100 Subject: [PATCH] Fix isolated build helper scripts (#1629) --- docs/changelog/1629.bugfix.rst | 1 + src/tox/helper/build_isolated.py | 2 +- src/tox/helper/build_requires.py | 2 +- tests/unit/package/test_package.py | 43 ++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 docs/changelog/1629.bugfix.rst diff --git a/docs/changelog/1629.bugfix.rst b/docs/changelog/1629.bugfix.rst new file mode 100644 index 000000000..cbb3fb6ab --- /dev/null +++ b/docs/changelog/1629.bugfix.rst @@ -0,0 +1 @@ +Fix ``TypeError`` when using isolated_build with backends that are not submodules (e.g. ``maturin``) diff --git a/src/tox/helper/build_isolated.py b/src/tox/helper/build_isolated.py index 59680ad6d..55ea41b8d 100644 --- a/src/tox/helper/build_isolated.py +++ b/src/tox/helper/build_isolated.py @@ -4,7 +4,7 @@ backend_spec = sys.argv[2] backend_obj = sys.argv[3] if len(sys.argv) >= 4 else None -backend = __import__(backend_spec, fromlist=[None]) +backend = __import__(backend_spec, fromlist=["_trash"]) if backend_obj: backend = getattr(backend, backend_obj) diff --git a/src/tox/helper/build_requires.py b/src/tox/helper/build_requires.py index 08bf94126..cd074f97f 100644 --- a/src/tox/helper/build_requires.py +++ b/src/tox/helper/build_requires.py @@ -4,7 +4,7 @@ backend_spec = sys.argv[1] backend_obj = sys.argv[2] if len(sys.argv) >= 3 else None -backend = __import__(backend_spec, fromlist=[None]) +backend = __import__(backend_spec, fromlist=["_trash"]) if backend_obj: backend = getattr(backend, backend_obj) diff --git a/tests/unit/package/test_package.py b/tests/unit/package/test_package.py index fc8da8bc6..d546ecc03 100644 --- a/tests/unit/package/test_package.py +++ b/tests/unit/package/test_package.py @@ -1,4 +1,5 @@ import re +import sys from tox.config import parseconfig from tox.package import get_package @@ -106,6 +107,48 @@ def test_make_sdist(initproj): assert sdist_new.stat().size > 10 +def test_build_backend_without_submodule(initproj, cmd): + # The important part of this test is that the build backend + # "inline_backend" is just a base package without a submodule. + # (Regression test for #1344) + initproj( + "magic-0.1", + filedefs={ + "tox.ini": """\ + [tox] + isolated_build = true + [testenv:.package] + basepython = {} + [testenv] + setenv = PYTHONPATH = {{toxinidir}} + """.format( + sys.executable, + ), + "pyproject.toml": """\ + [build-system] + requires = [] + build-backend = "inline_backend" + """, + # To trigger original bug, must be package with __init__.py + "inline_backend": { + "__init__.py": """\ + def get_requires_for_build_sdist(*args, **kwargs): + return ["pathlib2"] + + def build_sdist(sdist_directory, config_settings=None): + import pathlib2 + (pathlib2.Path(sdist_directory) / "magic-0.1.0.tar.gz").touch() + return "magic-0.1.0.tar.gz" + """, + }, + ".gitignore": ".tox", + }, + add_missing_setup_py=False, + ) + result = cmd("--sdistonly", "-e", "py", "-v", "-v") + result.assert_success(is_run_test_env=False) + + def test_package_inject(initproj, cmd, monkeypatch, tmp_path): monkeypatch.delenv(str("PYTHONPATH"), raising=False) initproj(