Skip to content

Commit

Permalink
Account for importlib_metadata in Python<3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed May 1, 2024
1 parent ca5c5a5 commit 455b77f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ flake8
testpath
setuptools>=30
tomli >=1.1.0 ; python_version<'3.11'
importlib-metadata; python_version<'3.8'
7 changes: 6 additions & 1 deletion src/pyproject_hooks/_in_process/_in_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ def find_spec(self, fullname, _path, _target=None):

def find_distributions(self, context=None):
# Delayed import: Python 3.7 does not contain importlib.metadata
from importlib.metadata import DistributionFinder, MetadataPathFinder
# 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)
Expand Down

0 comments on commit 455b77f

Please sign in to comment.