diff --git a/docs/changelog.d/+backend-config-settings.bugfix.rst b/docs/changelog.d/+backend-config-settings.bugfix.rst new file mode 100644 index 0000000..3976515 --- /dev/null +++ b/docs/changelog.d/+backend-config-settings.bugfix.rst @@ -0,0 +1 @@ +Expose ``ConfigSettings`` at runtime so wildcard imports from ``python_sbom.backend`` no longer fail. diff --git a/src/python_sbom/backend.py b/src/python_sbom/backend.py index d78a5bd..6ffd5cc 100644 --- a/src/python_sbom/backend.py +++ b/src/python_sbom/backend.py @@ -3,19 +3,18 @@ from __future__ import annotations import importlib +from collections.abc import Mapping as _Mapping from functools import cache, reduce from pathlib import Path -from typing import TYPE_CHECKING, Final, Protocol, cast +from typing import Final, Protocol, cast +from typing import TypeAlias as _TypeAlias from ._collect._revision import REVISION_FILE, default_revision, revision_record from ._collect._settings import settings_from_pyproject from ._errors import SbomError -if TYPE_CHECKING: - from collections.abc import Mapping - - #: the settings a frontend passes each hook, such as ``--config-settings`` of pip and build - ConfigSettings = Mapping[str, str | list[str]] | None +#: the settings a frontend passes each hook, such as ``--config-settings`` of pip and build +ConfigSettings: _TypeAlias = _Mapping[str, str | list[str]] | None # the hooks PEP 517 and PEP 660 let a backend leave out, which a frontend then replaces with its own default _OPTIONAL_HOOKS: Final[frozenset[str]] = frozenset({ diff --git a/tests/test_backend_star.py b/tests/test_backend_star.py new file mode 100644 index 0000000..7164a95 --- /dev/null +++ b/tests/test_backend_star.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +import subprocess +import sys + + +def test_backend_wildcard_import() -> None: + code = ( + "from collections.abc import Mapping\n" + "from python_sbom.backend import *\n" + "assert ConfigSettings == Mapping[str, str | list[str]] | None\n" + "assert callable(build_sdist) and callable(build_wheel)\n" + "print('imported')\n" + ) + assert subprocess.check_output([sys.executable, "-c", code], text=True) == "imported\n"