Skip to content
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

Fix isolated build helper scripts #1629

Merged
merged 1 commit into from
Jul 28, 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 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