Skip to content
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
3 changes: 2 additions & 1 deletion src/pyproject_api/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def __init__(self, backend_module, backend_obj):
self.backend_object = backend_obj
backend = importlib.import_module(self.backend_module)
if self.backend_object:
backend = getattr(backend, self.backend_object)
for name in self.backend_object.split("."):
backend = getattr(backend, name)
self.backend = backend

def __call__(self, name, *args, **kwargs):
Expand Down
22 changes: 16 additions & 6 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,31 @@ def test_create_args_from_folder_rejects_bad_build_system_type(tmp_path: Path, t
SubprocessFrontend.create_args_from_folder(tmp_path)


def test_backend_obj(tmp_path: Path) -> None:
toml = """
@pytest.mark.parametrize(
"backend_obj",
[
pytest.param("backend", id="attribute"),
pytest.param("backend:", id="trailing-colon"),
pytest.param("holder.backend", id="nested"),
pytest.param("holder.nested.backend", id="deeply-nested"),
],
)
def test_backend_obj(tmp_path: Path, backend_obj: str) -> None:
toml = f"""
[build-system]
requires=[]
build-backend = "build.api:backend:"
build-backend = "build.api:{backend_obj}"
backend-path=["."]
"""
api = """
from types import SimpleNamespace

class A:
def get_requires_for_build_sdist(self, config_settings=None):
return ["a"]

backend = A()
holder = SimpleNamespace(backend=backend, nested=SimpleNamespace(backend=backend))
"""
(tmp_path / "pyproject.toml").write_text(dedent(toml))
build = tmp_path / "build"
Expand All @@ -253,9 +265,7 @@ def get_requires_for_build_sdist(self, config_settings=None):
(build / "api.py").write_text(dedent(api))
frontend = SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(tmp_path)[:-1])
result = frontend.get_requires_for_build_sdist()
for left, right in zip(result.requires, (Requirement("a"),), strict=False):
assert isinstance(left, Requirement)
assert str(left) == str(right)
assert result.requires == (Requirement("a"),)


@pytest.mark.parametrize("of_type", ["wheel", "sdist"])
Expand Down
Loading