Skip to content

Commit 6b57973

Browse files
authored
Merge pull request #199 from abravalheri/issue-192-take2
Improve interop with `importlib.metadata`: variation without `importlib_metadata`
2 parents 9988edd + dba1817 commit 6b57973

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

src/pyproject_hooks/_in_process/_in_process.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ def find_spec(self, fullname, _path, _target=None):
106106

107107
return spec
108108

109+
if sys.version_info >= (3, 8):
110+
111+
def find_distributions(self, context=None):
112+
# Delayed import: Python 3.7 does not contain importlib.metadata
113+
from importlib.metadata import DistributionFinder, MetadataPathFinder
114+
115+
context = DistributionFinder.Context(path=self.backend_path)
116+
return MetadataPathFinder.find_distributions(context=context)
117+
109118

110119
def _supported_features():
111120
"""Return the list of options features supported by the backend.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Name: _test_bootstrap
2+
Version: 0.0.1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[_test_backend.importlib_metadata]
2+
hello = world
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from importlib.metadata import distribution
2+
3+
4+
def get_requires_for_build_sdist(config_settings):
5+
dist = distribution("_test_bootstrap") # discovered in backend-path
6+
ep = next(iter(dist.entry_points))
7+
return [ep.group, ep.name, ep.value]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
build-backend = 'intree_backend'
3+
backend-path = ['backend']

tests/test_inplace_hooks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ def test_intree_backend_loaded_from_correct_backend_path():
8989
assert res == ["intree_backend_called"]
9090

9191

92+
def test_intree_backend_importlib_metadata_interoperation():
93+
pytest.importorskip("importlib.metadata")
94+
95+
hooks = get_hooks("pkg_intree_metadata", backend="intree_backend")
96+
assert hooks.get_requires_for_build_sdist({}) == [
97+
"_test_backend.importlib_metadata",
98+
"hello",
99+
"world",
100+
]
101+
102+
92103
def install_finder_with_sitecustomize(directory, mapping):
93104
finder = f"""
94105
import sys

0 commit comments

Comments
 (0)