From 6cde6d567dfad5eefff43a425f9393f9aac745c4 Mon Sep 17 00:00:00 2001 From: ryneeverett Date: Sat, 2 Nov 2024 00:34:48 -0400 Subject: [PATCH] Update entry points access Switch from pkg_resources (deprecated) to importlib-metadata, and give a more helpful error when a service plugin isn't found. --- bugwarrior/collect.py | 15 +++++++-------- tests/test_docs.py | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/bugwarrior/collect.py b/bugwarrior/collect.py index 32d8bc94..21641927 100644 --- a/bugwarrior/collect.py +++ b/bugwarrior/collect.py @@ -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 @@ -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): diff --git a/tests/test_docs.py b/tests/test_docs.py index 04cd2c19..1afb0019 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -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 @@ -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')