Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: python/importlib_metadata
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.2.0
Choose a base ref
...
head repository: python/importlib_metadata
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.3.0
Choose a head ref
  • 5 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 25, 2024

  1. Expand the documentation of Distribution.locate_file to explain why '…

    …locate_file' does what it does and what the consequences are of not implementing it.
    
    Ref pypa/pip#11684
    jaraco committed Jul 25, 2024
    Copy the full SHA
    5ddd122 View commit details

Commits on Aug 1, 2024

  1. Disallow passing of 'dist' to EntryPoints.select.

    jaraco committed Aug 1, 2024
    Copy the full SHA
    875003a View commit details

Commits on Aug 19, 2024

  1. Remove MetadataPathFinder regardless of its position.

    Closes #500
    jaraco committed Aug 19, 2024
    Copy the full SHA
    6d9b766 View commit details
  2. Merge pull request #498 from python/feature/entry-points-disallow-dis…

    …t-match
    
    Disallow passing of 'dist' to EntryPoints.select.
    jaraco authored Aug 19, 2024
    Copy the full SHA
    5035755 View commit details
  3. Finalize

    jaraco committed Aug 19, 2024
    Copy the full SHA
    3c8e1ec View commit details
Showing with 48 additions and 6 deletions.
  1. +9 −0 NEWS.rst
  2. +11 −6 conftest.py
  3. +28 −0 importlib_metadata/__init__.py
9 changes: 9 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v8.3.0
======

Features
--------

- Disallow passing of 'dist' to EntryPoints.select.


v8.2.0
======

17 changes: 11 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -13,13 +13,18 @@ def pytest_configure():

def remove_importlib_metadata():
"""
Because pytest imports importlib_metadata, the coverage
reports are broken (#322). So work around the issue by
undoing the changes made by pytest's import of
importlib_metadata (if any).
Ensure importlib_metadata is not imported yet.
Because pytest or other modules might import
importlib_metadata, the coverage reports are broken (#322).
Work around the issue by undoing the changes made by a
previous import of importlib_metadata (if any).
"""
if sys.meta_path[-1].__class__.__name__ == 'MetadataPathFinder':
del sys.meta_path[-1]
sys.meta_path[:] = [
item
for item in sys.meta_path
if item.__class__.__name__ != 'MetadataPathFinder'
]
for mod in list(sys.modules):
if mod.startswith('importlib_metadata'):
del sys.modules[mod]
28 changes: 28 additions & 0 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
@@ -227,9 +227,26 @@ def matches(self, **params):
>>> ep.matches(attr='bong')
True
"""
self._disallow_dist(params)
attrs = (getattr(self, param) for param in params)
return all(map(operator.eq, params.values(), attrs))

@staticmethod
def _disallow_dist(params):
"""
Querying by dist is not allowed (dist objects are not comparable).
>>> EntryPoint(name='fan', value='fav', group='fag').matches(dist='foo')
Traceback (most recent call last):
...
ValueError: "dist" is not suitable for matching...
"""
if "dist" in params:
raise ValueError(
'"dist" is not suitable for matching. '
"Instead, use Distribution.entry_points.select() on a "
"located distribution."
)

def _key(self):
return self.name, self.value, self.group

@@ -373,6 +390,17 @@ def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
"""
Given a path to a file in this distribution, return a SimplePath
to it.
This method is used by callers of ``Distribution.files()`` to
locate files within the distribution. If it's possible for a
Distribution to represent files in the distribution as
``SimplePath`` objects, it should implement this method
to resolve such objects.
Some Distribution providers may elect not to resolve SimplePath
objects within the distribution by raising a
NotImplementedError, but consumers of such a Distribution would
be unable to invoke ``Distribution.files()``.
"""

@classmethod