Skip to content

Commit

Permalink
Update to new entry_points selection protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 1, 2021
1 parent 8698ca1 commit 473465e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v22.4.0
-------

* Use new entry points API from importlib_metadata 3.6.

v22.3.0
-------

Expand Down
7 changes: 2 additions & 5 deletions hook-keyring.backend.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Used by pyinstaller to expose hidden imports

try:
from importlib import metadata
except ImportError:
import importlib_metadata as metadata
import importlib_metadata as metadata


hiddenimports = [ep.value for ep in metadata.entry_points()['keyring.backends']]
hiddenimports = [ep.value for ep in metadata.entry_points(group='keyring.backends')]
8 changes: 2 additions & 6 deletions keyring/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

from typing import Optional

try:
from importlib import metadata # type: ignore
except ImportError:
import importlib_metadata as metadata # type: ignore
import importlib_metadata as metadata

from . import credentials, errors, util
from .util import properties
Expand Down Expand Up @@ -195,8 +192,7 @@ def _load_plugins():
`initialize_func` is optional, but will be invoked if callable.
"""
entry_points = metadata.entry_points().get('keyring.backends', [])
for ep in entry_points:
for ep in metadata.entry_points(group='keyring.backends'):
try:
log.debug('Loading %s', ep.name)
init_func = ep.load()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 >= 1; python_version < "3.8"
importlib_metadata >= 3.6
setup_requires = setuptools_scm[toml] >= 3.4.1

[options.packages.find]
Expand Down
12 changes: 5 additions & 7 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try:
from importlib import metadata # type: ignore
except ImportError:
import importlib_metadata as metadata # type: ignore
import importlib_metadata as metadata

from keyring import backend

Expand All @@ -11,13 +8,14 @@ def test_entry_point():
Keyring provides exactly one 'keyring' console script
that's a callable.
"""
scripts = dict(metadata.entry_points()['console_scripts'])
assert callable(scripts['keyring'].load())
matches = metadata.entry_points(group='console_scripts', name='keyring')
(script,) = matches
assert callable(script.load())


def test_missing_metadata(monkeypatch):
"""
_load_plugins should pass when keyring metadata is missing.
"""
monkeypatch.setattr(metadata, 'entry_points', dict)
monkeypatch.setattr(metadata, 'entry_points', metadata.EntryPoints)
backend._load_plugins()

0 comments on commit 473465e

Please sign in to comment.