Skip to content

Commit

Permalink
Fix isolated build helper scripts (#1629)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt authored Jul 28, 2020
1 parent 5704456 commit f6e60fd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/1629.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``TypeError`` when using isolated_build with backends that are not submodules (e.g. ``maturin``)
2 changes: 1 addition & 1 deletion src/tox/helper/build_isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/tox/helper/build_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
43 changes: 43 additions & 0 deletions tests/unit/package/test_package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import sys

from tox.config import parseconfig
from tox.package import get_package
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f6e60fd

Please sign in to comment.