Skip to content

Commit f6e60fd

Browse files
authored
Fix isolated build helper scripts (#1629)
1 parent 5704456 commit f6e60fd

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

docs/changelog/1629.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``TypeError`` when using isolated_build with backends that are not submodules (e.g. ``maturin``)

src/tox/helper/build_isolated.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
backend_spec = sys.argv[2]
55
backend_obj = sys.argv[3] if len(sys.argv) >= 4 else None
66

7-
backend = __import__(backend_spec, fromlist=[None])
7+
backend = __import__(backend_spec, fromlist=["_trash"])
88
if backend_obj:
99
backend = getattr(backend, backend_obj)
1010

src/tox/helper/build_requires.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
backend_spec = sys.argv[1]
55
backend_obj = sys.argv[2] if len(sys.argv) >= 3 else None
66

7-
backend = __import__(backend_spec, fromlist=[None])
7+
backend = __import__(backend_spec, fromlist=["_trash"])
88
if backend_obj:
99
backend = getattr(backend, backend_obj)
1010

tests/unit/package/test_package.py

+43
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import sys
23

34
from tox.config import parseconfig
45
from tox.package import get_package
@@ -106,6 +107,48 @@ def test_make_sdist(initproj):
106107
assert sdist_new.stat().size > 10
107108

108109

110+
def test_build_backend_without_submodule(initproj, cmd):
111+
# The important part of this test is that the build backend
112+
# "inline_backend" is just a base package without a submodule.
113+
# (Regression test for #1344)
114+
initproj(
115+
"magic-0.1",
116+
filedefs={
117+
"tox.ini": """\
118+
[tox]
119+
isolated_build = true
120+
[testenv:.package]
121+
basepython = {}
122+
[testenv]
123+
setenv = PYTHONPATH = {{toxinidir}}
124+
""".format(
125+
sys.executable,
126+
),
127+
"pyproject.toml": """\
128+
[build-system]
129+
requires = []
130+
build-backend = "inline_backend"
131+
""",
132+
# To trigger original bug, must be package with __init__.py
133+
"inline_backend": {
134+
"__init__.py": """\
135+
def get_requires_for_build_sdist(*args, **kwargs):
136+
return ["pathlib2"]
137+
138+
def build_sdist(sdist_directory, config_settings=None):
139+
import pathlib2
140+
(pathlib2.Path(sdist_directory) / "magic-0.1.0.tar.gz").touch()
141+
return "magic-0.1.0.tar.gz"
142+
""",
143+
},
144+
".gitignore": ".tox",
145+
},
146+
add_missing_setup_py=False,
147+
)
148+
result = cmd("--sdistonly", "-e", "py", "-v", "-v")
149+
result.assert_success(is_run_test_env=False)
150+
151+
109152
def test_package_inject(initproj, cmd, monkeypatch, tmp_path):
110153
monkeypatch.delenv(str("PYTHONPATH"), raising=False)
111154
initproj(

0 commit comments

Comments
 (0)