Skip to content

Commit

Permalink
Merge pull request #12 from sopel-irc/rm-pkg_resources
Browse files Browse the repository at this point in the history
managers, meta: migrate off of `pkg_resources` to `importlib_metadata`
  • Loading branch information
Exirel authored Oct 20, 2024
2 parents 1d35df4 + 425e729 commit 67954a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ classifiers = [
requires-python = ">=3.8"
dependencies = [
"sopel>=7.1",
# sopel also requires both of the below, but it's best to be explicit
"requests",
"importlib_metadata>=3.6",
]

[project.urls]
Expand Down
20 changes: 11 additions & 9 deletions sopel_help/managers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Sopel Help Managers."""

import pkg_resources
import importlib_metadata

PROVIDERS_ENTRY_POINT = 'sopel_help.providers'

Expand All @@ -18,8 +18,8 @@ def provider(self):
def provider_names(self):
"""Names of the available providers."""
if self._provider_list is None:
entry_points = pkg_resources.iter_entry_points(
PROVIDERS_ENTRY_POINT)
entry_points = importlib_metadata.entry_points(
group=PROVIDERS_ENTRY_POINT)
self._provider_list = [
entry_point.name
for entry_point in entry_points
Expand All @@ -37,16 +37,18 @@ def load_provider(self, name):
:return: a provider instance
:rtype: :class:`sopel_help.providers.AbstractProvider`
The provider will be loaded from an entry point and then instanciated
The provider will be loaded from an entry point and then instantiated
to be returned as is (no setup, no configure).
"""
entry_points = pkg_resources.iter_entry_points(
PROVIDERS_ENTRY_POINT, name)
# 1. get EntryPoints matching the group and name
entry_points = importlib_metadata.entry_points(
group=PROVIDERS_ENTRY_POINT, name=name)

# 2. get just the EntryPoint matching `name`
try:
entry_point = next(entry_points)
except StopIteration as err:
raise RuntimeError('Cannot found help provider %s' % name) from err
entry_point = entry_points[name]
except KeyError:
raise RuntimeError('Cannot find help provider %r' % name) from None

# 3. load the entry point
provider_maker = entry_point.load()
Expand Down
1 change: 1 addition & 0 deletions sopel_help/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import urllib

import requests

from sopel.tools import get_logger

from sopel_help import mixins
Expand Down

0 comments on commit 67954a3

Please sign in to comment.