diff --git a/src/pyproject_hooks/_in_process/_in_process.py b/src/pyproject_hooks/_in_process/_in_process.py index 0645b0c..4f0bc24 100644 --- a/src/pyproject_hooks/_in_process/_in_process.py +++ b/src/pyproject_hooks/_in_process/_in_process.py @@ -106,6 +106,18 @@ def find_spec(self, fullname, _path, _target=None): return spec + def find_distributions(self, context=None): + # Delayed import: Python 3.7 does not contain importlib.metadata + # If this method is being called it must be because + # `importlib.metadata`/`importlib_metadata` is available. + try: + from importlib_metadata import DistributionFinder, MetadataPathFinder + except ImportError: + from importlib.metadata import DistributionFinder, MetadataPathFinder + + context = DistributionFinder.Context(path=self.backend_path) + return MetadataPathFinder.find_distributions(context=context) + def _supported_features(): """Return the list of options features supported by the backend. diff --git a/tests/samples/pkg_intree_metadata/backend/_test_boostrap-0.0.1.dist-info/METADATA b/tests/samples/pkg_intree_metadata/backend/_test_boostrap-0.0.1.dist-info/METADATA new file mode 100644 index 0000000..aaf174b --- /dev/null +++ b/tests/samples/pkg_intree_metadata/backend/_test_boostrap-0.0.1.dist-info/METADATA @@ -0,0 +1,2 @@ +Name: _test_bootstrap +Version: 0.0.1 diff --git a/tests/samples/pkg_intree_metadata/backend/_test_boostrap-0.0.1.dist-info/entry_points.txt b/tests/samples/pkg_intree_metadata/backend/_test_boostrap-0.0.1.dist-info/entry_points.txt new file mode 100644 index 0000000..d62a9c9 --- /dev/null +++ b/tests/samples/pkg_intree_metadata/backend/_test_boostrap-0.0.1.dist-info/entry_points.txt @@ -0,0 +1,2 @@ +[_test_backend.importlib_metadata] +hello = world diff --git a/tests/samples/pkg_intree_metadata/backend/intree_backend.py b/tests/samples/pkg_intree_metadata/backend/intree_backend.py new file mode 100644 index 0000000..9748082 --- /dev/null +++ b/tests/samples/pkg_intree_metadata/backend/intree_backend.py @@ -0,0 +1,7 @@ +from importlib.metadata import distribution + + +def get_requires_for_build_sdist(config_settings): + dist = distribution("_test_bootstrap") # discovered in backend-path + ep = next(iter(dist.entry_points)) + return [ep.group, ep.name, ep.value] diff --git a/tests/samples/pkg_intree_metadata/pyproject.toml b/tests/samples/pkg_intree_metadata/pyproject.toml new file mode 100644 index 0000000..fd4e8cb --- /dev/null +++ b/tests/samples/pkg_intree_metadata/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +build-backend = 'intree_backend' +backend-path = ['backend'] diff --git a/tests/test_inplace_hooks.py b/tests/test_inplace_hooks.py index 6b73ceb..1df12d6 100644 --- a/tests/test_inplace_hooks.py +++ b/tests/test_inplace_hooks.py @@ -89,6 +89,17 @@ def test_intree_backend_loaded_from_correct_backend_path(): assert res == ["intree_backend_called"] +def test_intree_backend_importlib_metadata_interoperation(): + pytest.importorskip("importlib.metadata") + + hooks = get_hooks("pkg_intree_metadata", backend="intree_backend") + assert hooks.get_requires_for_build_sdist({}) == [ + "_test_backend.importlib_metadata", + "hello", + "world", + ] + + def install_finder_with_sitecustomize(directory, mapping): finder = f""" import sys