Skip to content
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
8 changes: 4 additions & 4 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ class EntryPoint:
...
ValueError: ('Invalid object reference...invalid-name...

The same thing happens on construction.
Construction never raises; the value is validated only when
accessed or loaded.

>>> EntryPoint(name=None, group=None, value='invalid-name')
>>> ep = EntryPoint(name=None, group=None, value='invalid-name')
>>> ep.load()
Traceback (most recent call last):
...
ValueError: ('Invalid object reference...invalid-name...
Expand Down Expand Up @@ -217,8 +219,6 @@ class EntryPoint:

def __init__(self, name: str, value: str, group: str) -> None:
vars(self).update(name=name, value=value, group=group)
# resolve the value now, raising ValueError if it's invalid
_ = self.module

def load(self) -> Any:
"""Load the entry point from its definition. If only a module
Expand Down
4 changes: 4 additions & 0 deletions newsfragments/523.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Restored lazy validation of ``EntryPoint.value``, deferring the ``ValueError``
for an invalid value until a component is accessed or the entry point is
loaded, so one malformed entry point no longer prevents entry points in other
groups from being selected.
30 changes: 30 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,36 @@ def test_entry_points_missing_name(self):
def test_entry_points_missing_group(self):
assert entry_points(group='missing') == ()

def test_entry_points_invalid_value_in_other_group(self):
"""
An invalid value in one group should not prevent entry points
in other groups from being selected.
"""
alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path())
self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
alt_pkg = {
"invalid_entry_points-1.0.0.dist-info": {
"METADATA": """
Name: invalid-entry-points
Version: 1.0.0
""",
"entry_points.txt": """
[selected]
valid = mod:main

[unselected]
invalid = invalid-name
""",
},
}
fixtures.build_files(alt_pkg, alt_site_dir)

assert [ep.name for ep in entry_points(group='selected')] == ['valid']

# the invalid value is still rejected when the entry point is used
with self.assertRaises(ValueError):
entry_points(group='unselected')['invalid'].load()

def test_entry_points_allows_no_attributes(self):
ep = entry_points().select(group='entries', name='main')
with self.assertRaises(AttributeError):
Expand Down
Loading