changeset 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 51a355095838
files CHANGES.txt configmix/__init__.py
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)