Skip to content

Commit

Permalink
Avoid logging warning with no config file is present. Fixes #635.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 23, 2023
1 parent 560eca8 commit c1e291b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 6 additions & 1 deletion keyring/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ def _config_path():
return platform.config_root() / 'keyringrc.cfg'


def _ensure_path(path):
if not path.exists():
raise FileNotFoundError(path)


def load_config() -> typing.Optional[backend.KeyringBackend]:
"""Load a keyring using the config file in the config root."""

config = configparser.RawConfigParser()
try:
config.read(_config_path(), encoding='utf-8')
config.read(_ensure_path(_config_path()), encoding='utf-8')
except FileNotFoundError:
return None
_load_keyring_path(config)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/635.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid logging warning when no config file is present.
3 changes: 0 additions & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

import keyring.core


Expand All @@ -11,7 +9,6 @@ def test_init_recommended(monkeypatch):
keyring.core.init_backend(keyring.core.recommended)


@pytest.mark.xfail(reason="#635")
def test_load_config_missing(caplog):
assert keyring.core.load_config() is None
assert not caplog.records

0 comments on commit c1e291b

Please sign in to comment.