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 2, 2024
1 parent 97c1cb6 commit 6cde6d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions bugwarrior/collect.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import copy
from importlib.metadata import entry_points
import logging
import multiprocessing
import time

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
4 changes: 2 additions & 2 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import docutils.core
import glob
from importlib.metadata import entry_points
import os.path
import pathlib
import pkg_resources
import re
import socket
import subprocess
Expand Down Expand Up @@ -69,7 +69,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 6cde6d5

Please sign in to comment.