Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use external importlib_metadata package when python < 3.8 #507

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion hook-keyring.backend.py
Original file line number Diff line number Diff line change
@@ -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')]
13 changes: 11 additions & 2 deletions keyring/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
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 >= 3.6
importlib_metadata >= 3.6; python_version < "3.8"
setup_requires = setuptools_scm[toml] >= 3.4.1

[options.packages.find]
Expand Down
17 changes: 14 additions & 3 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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())

Expand All @@ -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()