Skip to content

Commit 03ee557

Browse files
committed
fix: python3.9 can contain duplicates
* importlib.metadata.entry_points of python3.9 can contain duplicates. duplicates create errors on the caller side. the rest of the code assumes that the return value has no duplicates.
1 parent 9587e5c commit 03ee557

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

invenio_base/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def converter_loader(app, entry_points=None, modules=None):
280280
"""
281281
if entry_points:
282282
for entry_point in entry_points:
283-
for ep in set(iter_entry_points(group=entry_point)):
283+
for ep in iter_entry_points(group=entry_point):
284284
try:
285285
app.url_map.converters[ep.name] = ep.load()
286286
except Exception:
@@ -301,7 +301,7 @@ def _loader(app, init_func, entry_points=None, modules=None):
301301
"""
302302
if entry_points:
303303
for entry_point in entry_points:
304-
for ep in set(iter_entry_points(group=entry_point)):
304+
for ep in iter_entry_points(group=entry_point):
305305
try:
306306
init_func(ep.load())
307307
except Exception:

invenio_base/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def migrate_secret_key(old_key):
7070
raise click.ClickException("SECRET_KEY is not set in the configuration.")
7171

7272
migrators = []
73-
for ep in set(entry_points("invenio_base.secret_key")):
73+
for ep in entry_points("invenio_base.secret_key"):
7474
try:
7575
migrators.append(ep.load())
7676
except Exception:

invenio_base/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ def entry_points(group):
2626
# in the tests there is a line which patches the return value of
2727
# importlib.metadata.entry_points with a list. this works for
2828
# python>=3.10 but not for 3.9
29+
# the return value of .get can contain duplicates. the simplest way to
30+
# remove is the set() call, to still return a list, list() is called on
31+
# set()
2932
if isinstance(eps, dict):
30-
eps = eps.get(group, [])
33+
eps = list(set(eps.get(group, [])))
3134
else:
3235
eps = m.entry_points(group=group)
3336

0 commit comments

Comments
 (0)