# HG changeset patch # User Franz Glasner # Date 1557387471 -7200 # Node ID 6f0f39a9a46f9563ed4aab0d047beec2d8a32c0b # Parent 2034da70f8fdb8c563aefd000976f5337cde2079 configmix.load() and .safe_load() got a new keyword argument "extras" to be merged in as last configuration dictionary diff -r 2034da70f8fd -r 6f0f39a9a46f CHANGES.txt --- a/CHANGES.txt Thu May 09 09:27:23 2019 +0200 +++ b/CHANGES.txt Thu May 09 09:37:51 2019 +0200 @@ -17,6 +17,16 @@ :released: unreleased .. change:: + :tags: feature + + :py:func:`configmix.load` and :py:func:`configmix.safe_load` got a + new keyword argument `extras` that (if given) will be used as the + *last* configuration dictionary to be merged into the configuration. + + This can be used to overwrite configuration file settings from + commandline arguments. + + .. change:: :tags: bugfix :py:func:`configmix.safe_load` did some preliminary unsafe merges diff -r 2034da70f8fd -r 6f0f39a9a46f configmix/__init__.py --- a/configmix/__init__.py Thu May 09 09:27:23 2019 +0200 +++ b/configmix/__init__.py Thu May 09 09:37:51 2019 +0200 @@ -53,17 +53,26 @@ settings where the settings from `files` are merged into :type defaults: dict-alike or None + :keyword extras: optional configuration dictionary that will applied + last + + Use this for example to overwrite configuration file + settings from commandline arguments. + :type extras: dict-alike or None :returns: the configuration :rtype: ~configmix.config.Configuration """ defaults = kwargs.get("defaults") + extras = kwargs.get("extras") if defaults is None: ex = Configuration() else: ex = merge(None, Configuration(defaults)) for f in files: ex = merge(_load_cfg_from_file(f), ex) + if extras: + ex = merge(Configuration(extras), ex) return Configuration(ex) @@ -73,12 +82,15 @@ """ defaults = kwargs.get("defaults") + extras = kwargs.get("extras") if defaults is None: ex = Configuration() else: ex = safe_merge(None, Configuration(defaults)) for f in files: ex = safe_merge(_load_cfg_from_file(f), ex) + if extras: + ex = safe_merge(Configuration(extras), ex) return Configuration(ex)