commit 03136450f0f550fe9dbe586054d8f83733124b56 Author: juga0 juga@riseup.net Date: Sun Nov 18 10:05:26 2018 +0000
config: continue when the file is not found
Continue running with defaults when the config argument is provided but not found. This could be the case of system packages. --- CHANGELOG.md | 2 ++ sbws/util/config.py | 9 ++++++--- tests/unit/util/test_config.py | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md index e5750bc..d9a6c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Make sbws round to 3 significant figures in torflow rounding mode, rather than rounding to the nearest 1000 kilobytes (#28442). +- Continue running with defaults when the config argument is provided + but not found (#28500).
## [1.0.2] - 2018-11-10
diff --git a/sbws/util/config.py b/sbws/util/config.py index 80c2761..67ec0e0 100644 --- a/sbws/util/config.py +++ b/sbws/util/config.py @@ -10,7 +10,7 @@ from string import Template from tempfile import NamedTemporaryFile from sbws.globals import (DEFAULT_CONFIG_PATH, DEFAULT_LOG_CONFIG_PATH, USER_CONFIG_PATH, SUPERVISED_RUN_DPATH, - SUPERVISED_USER_CONFIG_PATH, fail_hard) + SUPERVISED_USER_CONFIG_PATH)
_ALPHANUM = 'abcdefghijklmnopqrstuvwxyz' _ALPHANUM += _ALPHANUM.upper() @@ -66,8 +66,11 @@ def _get_user_config(args, conf=None): assert isinstance(conf, ConfigParser) if args.config: if not os.path.isfile(args.config): - fail_hard('Configuration file %s not found.', args.config) - return _extend_config(conf, args.config) + # XXX: The logger is not configured at this stage, + # sbws should start with a logger before reading configurations. + print('Configuration file %s not found, using defaults.' % + args.config) + return conf user_config_path = _obtain_user_conf_path() if os.path.isfile(user_config_path): return _extend_config(conf, user_config_path) diff --git a/tests/unit/util/test_config.py b/tests/unit/util/test_config.py index e259e52..e3aba98 100644 --- a/tests/unit/util/test_config.py +++ b/tests/unit/util/test_config.py @@ -230,3 +230,8 @@ def test_nickname(): d = {'n': nick} valid, reason = con._validate_nickname(d, 'n') assert not valid, reason + + +def test_config_arg_provided_but_no_found(args, conf): + args.config = 'non_existing_file' + con._get_user_config(args, conf=None)