Skip to content

Commit

Permalink
Merge pull request #199 from abravalheri/issue-192-take2
Browse files Browse the repository at this point in the history
Improve interop with `importlib.metadata`: variation without `importlib_metadata`
  • Loading branch information
takluyver authored Sep 29, 2024
2 parents 9988edd + dba1817 commit 6b57973
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pyproject_hooks/_in_process/_in_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ def find_spec(self, fullname, _path, _target=None):

return spec

if sys.version_info >= (3, 8):

def find_distributions(self, context=None):
# Delayed import: Python 3.7 does not contain importlib.metadata
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name: _test_bootstrap
Version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[_test_backend.importlib_metadata]
hello = world
7 changes: 7 additions & 0 deletions tests/samples/pkg_intree_metadata/backend/intree_backend.py
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 3 additions & 0 deletions tests/samples/pkg_intree_metadata/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
build-backend = 'intree_backend'
backend-path = ['backend']
11 changes: 11 additions & 0 deletions tests/test_inplace_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b57973

Please sign in to comment.