Skip to content

Commit d78210d

Browse files
authored
Merge pull request ckan#8992 from ckan/update-iter-entry-points
Replace usage of pkg_resources.iter_entry_points, update exception message
2 parents 407d3fb + 8d03774 commit d78210d

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

changes/8992.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace usage of pkg_resources.iter_entry_points, update exception message

ckan/cli/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
from collections import defaultdict
66
from typing import Optional
7-
from pkg_resources import iter_entry_points
7+
from importlib.metadata import entry_points
88

99
import click
1010
import sys
@@ -187,7 +187,7 @@ def _get_commands_from_entry_point(entry_point: str = 'ckan.click_command'):
187187
188188
"""
189189
registered_entries = {}
190-
for entry in iter_entry_points(entry_point): # type: ignore
190+
for entry in entry_points(group=entry_point):
191191
if entry.name in registered_entries:
192192
error_shout((
193193
u'Attempt to override entry_point `{name}`.\n'

ckan/plugins/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def __init__(self, name: str):
3636
self.name = name
3737

3838
def __str__(self):
39-
return f"Interface {self.name} does not exist"
39+
return (
40+
f"Plugin '{self.name}' not found.\n\n"
41+
"Did you install the 'ckanext-*' Python package that contains the plugin?"
42+
)
4043

4144

4245
class Interface:

ckan/plugins/core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from contextlib import contextmanager
88
from typing import Generic, Iterator, TypeVar
99
from typing_extensions import TypeGuard
10-
from pkg_resources import iter_entry_points
10+
from importlib.metadata import entry_points
1111

1212

1313
from ckan.common import config, aslist
@@ -240,10 +240,10 @@ def _get_service(plugin_name: str) -> Plugin:
240240
>>> assert isinstance(plugin, ActivityPlugin)
241241
"""
242242
for group in GROUPS:
243-
iterator = iter_entry_points(group=group,name=plugin_name) # type: ignore
244-
plugin = next(iterator, None)
245-
if plugin:
246-
return plugin.load()(name=plugin_name)
243+
ep = entry_points(group=group, name=plugin_name)
244+
if ep:
245+
return ep[plugin_name].load()(name=plugin_name)
246+
247247
raise PluginNotFoundException(plugin_name)
248248

249249

0 commit comments

Comments
 (0)