diff --git a/hook-keyring.backend.py b/hook-keyring.backend.py index 16d4044f..33b7a653 100644 --- a/hook-keyring.backend.py +++ b/hook-keyring.backend.py @@ -1,6 +1,11 @@ # Used by pyinstaller to expose hidden imports -import importlib_metadata as metadata +import sys + +if sys.version_info < (3, 8): + import importlib_metadata as metadata +else: + import importlib.metadata as metadata hiddenimports = [ep.value for ep in metadata.entry_points(group='keyring.backends')] diff --git a/keyring/backend.py b/keyring/backend.py index ee6b256e..c46474a9 100644 --- a/keyring/backend.py +++ b/keyring/backend.py @@ -5,11 +5,15 @@ import os import abc import logging +import sys import operator from typing import Optional -import importlib_metadata as metadata +if sys.version_info < (3, 8): + import importlib_metadata as metadata +else: + import importlib.metadata as metadata from . import credentials, errors, util from .util import properties @@ -195,7 +199,12 @@ def _load_plugins(): `initialize_func` is optional, but will be invoked if callable. """ - for ep in metadata.entry_points(group='keyring.backends'): + if sys.version_info < (3, 8): + eps = metadata.entry_points(group='keyring.backends') + else: + eps = metadata.entry_points()['keyring.backends'] + + for ep in eps: try: log.debug('Loading %s', ep.name) init_func = ep.load() diff --git a/setup.cfg b/setup.cfg index aa82e2e9..54e2ec60 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,7 +25,7 @@ install_requires = pywin32-ctypes!=0.1.0,!=0.1.1; sys_platform=="win32" SecretStorage>=3.2; sys_platform=="linux" jeepney>=0.4.2; sys_platform=="linux" - importlib_metadata >= 3.6 + importlib_metadata >= 3.6; python_version < "3.8" setup_requires = setuptools_scm[toml] >= 3.4.1 [options.packages.find] diff --git a/tests/test_packaging.py b/tests/test_packaging.py index e707d427..81d54a6e 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -1,4 +1,9 @@ -import importlib_metadata as metadata +import sys + +if sys.version_info < (3, 8): + import importlib_metadata as metadata +else: + import importlib.metadata as metadata from keyring import backend @@ -8,7 +13,12 @@ def test_entry_point(): Keyring provides exactly one 'keyring' console script that's a callable. """ - matches = metadata.entry_points(group='console_scripts', name='keyring') + if sys.version_info < (3, 8): + matches = metadata.entry_points(group='console_scripts', name='keyring') + else: + scripts = metadata.entry_points()['console_scripts'] + matches = tuple([ep for ep in scripts if ep.name == 'keyring']) + print(matches) # TODO: remove, this is just to verify why tests are failing (script,) = matches assert callable(script.load()) @@ -17,5 +27,6 @@ def test_missing_metadata(monkeypatch): """ _load_plugins should pass when keyring metadata is missing. """ - monkeypatch.setattr(metadata, 'entry_points', metadata.EntryPoints().select) + if sys.version_info < (3, 8): + monkeypatch.setattr(metadata, 'entry_points', metadata.EntryPoints().select) backend._load_plugins()