Skip to content

Commit

Permalink
Update entry points access
Browse files Browse the repository at this point in the history
Switch from pkg_resources (deprecated) to importlib-metadata, and give a
more helpful error when a service plugin isn't found.
  • Loading branch information
ryneeverett committed Nov 16, 2024
1 parent 8997a5c commit 1bef94c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
15 changes: 7 additions & 8 deletions bugwarrior/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import multiprocessing
import time

from importlib_metadata import entry_points
from jinja2 import Template
from pkg_resources import iter_entry_points

from taskw.task import Task

Expand All @@ -15,14 +15,13 @@
SERVICE_FINISHED_ERROR = 1


def get_service(service_name):
epoint = iter_entry_points(group='bugwarrior.service', name=service_name)
def get_service(service_name: str):
try:
epoint = next(epoint)
except StopIteration:
return None

return epoint.load()
(service,) = entry_points(group='bugwarrior.service', name=service_name)
except ValueError as e:
raise ValueError(f"Configured service '{service_name}' not found. "
"Is it installed? Or misspelled?") from e
return service.load()


def _aggregate_issues(conf, main_section, target, queue):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import glob
import os.path
import pathlib
import pkg_resources
import re
import socket
import subprocess
import tempfile
import unittest

from importlib_metadata import entry_points

DOCS_PATH = pathlib.Path(__file__).parent / '../bugwarrior/docs'

try:
Expand Down Expand Up @@ -69,7 +70,7 @@ def test_manpage_build_without_warning(self):
def test_registered_services_are_documented(self):
registered_services = set(
e.name for e in
pkg_resources.iter_entry_points(group='bugwarrior.service'))
entry_points(group='bugwarrior.service'))

documented_services = set()
services_paths = os.listdir(DOCS_PATH / 'services')
Expand Down

0 comments on commit 1bef94c

Please sign in to comment.