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

Initialise backend on first use instead of on import #480

Merged
merged 2 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
v21.6.0
-------

* #403: Keyring no longer eagerly initializes the backend
on import, but instead defers the backend initialization
until a keyring is accessed. Any callers reliant on this
early intialization behavior may need to call
``keyring.core.init_backend()`` to explicitly initialize
the detected backend.

v21.5.0
-------

Expand Down
14 changes: 6 additions & 8 deletions keyring/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def set_keyring(keyring):

def get_keyring():
"""Get current keyring backend."""
if _keyring_backend is None:
init_backend()
return _keyring_backend


Expand All @@ -50,22 +52,22 @@ def disable():

def get_password(service_name, username):
"""Get password from the specified service."""
return _keyring_backend.get_password(service_name, username)
return get_keyring().get_password(service_name, username)


def set_password(service_name, username, password):
"""Set password for the user in the specified service."""
_keyring_backend.set_password(service_name, username, password)
get_keyring().set_password(service_name, username, password)


def delete_password(service_name, username):
"""Delete the password for the user in the specified service."""
_keyring_backend.delete_password(service_name, username)
get_keyring().delete_password(service_name, username)


def get_credential(service_name, username):
"""Get a Credential for the specified service."""
return _keyring_backend.get_credential(service_name, username)
return get_keyring().get_credential(service_name, username)


def recommended(backend):
Expand Down Expand Up @@ -187,7 +189,3 @@ def _load_keyring_path(config):
sys.path.insert(0, path)
except (configparser.NoOptionError, configparser.NoSectionError):
pass


# init the _keyring_backend
init_backend()