Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/__init__.py @ 221:6f0f39a9a46f
configmix.load() and .safe_load() got a new keyword argument "extras" to be merged in as last configuration dictionary
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 09 May 2019 09:37:51 +0200 |
| parents | 2034da70f8fd |
| children | 90dd0d04b926 |
line wrap: on
line diff
--- 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)
