diff --git a/requirements.in b/requirements.in index eebecb71..a6abb559 100644 --- a/requirements.in +++ b/requirements.in @@ -11,3 +11,4 @@ python-dateutil pytz; python_version < '3.9' PyYAML requests +importlib-metadata; python_version < '3.10' diff --git a/src/pushsource/_impl/source.py b/src/pushsource/_impl/source.py index 6a4318f0..08447500 100644 --- a/src/pushsource/_impl/source.py +++ b/src/pushsource/_impl/source.py @@ -2,10 +2,15 @@ import functools import logging import os +import sys from threading import Lock from urllib import parse -import pkg_resources +if sys.version_info >= (3, 10): # pragma: no cover + from importlib.metadata import entry_points +else: + # for older python use non-standard compatible module + from importlib_metadata import entry_points from pushsource._impl.helpers import wait_exist @@ -128,12 +133,11 @@ def __ensure_init(cls): @classmethod def __load_entrypoints(cls): - for ep in pkg_resources.iter_entry_points("pushsource"): + for ep in entry_points(group="pushsource"): # Note we're just trying to import the entry point's module, not # call any method. - # resolve vs load is for different versions of pkg_resources. # Result is assigned to a var to avoid a pylint warning. - _ = ep.resolve() if hasattr(ep, "resolve") else ep.load(require=False) + _ = ep.load() @classmethod def get(cls, source_url, **kwargs): diff --git a/tests/source/test_source_entrypoint.py b/tests/source/test_source_entrypoint.py index 9908d85a..c82dfacf 100644 --- a/tests/source/test_source_entrypoint.py +++ b/tests/source/test_source_entrypoint.py @@ -19,7 +19,7 @@ def __init__(self): created1.append(True) @classmethod - def resolve(cls): + def load(cls): Source.register_backend("backend1", Backend1) class Backend2(object): @@ -27,18 +27,18 @@ def __init__(self): created2.append(True) @classmethod - def resolve(cls): + def load(cls): Source.register_backend("backend2", Backend2) - with patch("pkg_resources.iter_entry_points") as iter_ep: - iter_ep.return_value = [Backend1, Backend2] + with patch("pushsource._impl.source.entry_points") as ep: + ep.return_value = [Backend1, Backend2] # I should be able to get instances of those two backends assert Source.get("backend1:") assert Source.get("backend2:") # It should have found them via the expected entry point group - iter_ep.assert_called_once_with("pushsource") + ep.assert_called_once_with(group="pushsource") # Should have created one instance of each assert created1 == [True]