From c7a557dfe10a658d2fe534c0921382b5587c679c 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 | 5 +++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bugwarrior/collect.py b/bugwarrior/collect.py index 32d8bc94..8d435461 100644 --- a/bugwarrior/collect.py +++ b/bugwarrior/collect.py @@ -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 @@ -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..953a39e0 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -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: @@ -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')