Skip to content

Improve interop with importlib.metadata: variation without importlib_metadata #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 29, 2024
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
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
Loading