Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

managers, meta: migrate off of pkg_resources to importlib_metadata #12

Merged
merged 1 commit into from
Oct 20, 2024
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
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