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

Unnecessary dependency on importlib_metadata in Python 3.8+ #515

Closed
nchepanov opened this issue Jun 3, 2021 · 1 comment
Closed

Unnecessary dependency on importlib_metadata in Python 3.8+ #515

nchepanov opened this issue Jun 3, 2021 · 1 comment

Comments

@nchepanov
Copy link

nchepanov commented Jun 3, 2021

Describe the bug
The package declares an install_requires dependency on importlib_metadata >= 3.6, this however is not necessary for Python 3.8+: https://docs.python.org/3.8/library/importlib.metadata.html#

Proposal

Change the package setup.py to not require importlib_metadata in Python 3.8+ and use conditional imports.

Please let me know if you'd like a PR

diff --git a/hook-keyring.backend.py b/hook-keyring.backend.py
index 16d4044..c453f21 100644
--- a/hook-keyring.backend.py
+++ b/hook-keyring.backend.py
@@ -1,6 +1,9 @@
 # Used by pyinstaller to expose hidden imports

-import importlib_metadata as metadata
+try:
+    import importlib.metadata as metadata
+except ImportError:
+    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 ee6b256..3041faf 100644
--- a/keyring/backend.py
+++ b/keyring/backend.py
@@ -9,7 +9,11 @@ import operator

 from typing import Optional

-import importlib_metadata as metadata
+try:
+    import importlib.metadata as metadata
+except ImportError:
+    import importlib_metadata as metadata
+

 from . import credentials, errors, util
 from .util import properties
diff --git a/setup.cfg b/setup.cfg
index aa82e2e..54e2ec6 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]
@mitya57
Copy link
Collaborator

mitya57 commented Jun 3, 2021

Please look at closed issues, this was already discussed several times.

Keyring is using the new API which is not available in Python 3.8 or 3.9, see #503 (comment) for details.

@mitya57 mitya57 closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants