From c6382e00e088c533efa78c58d42ecf67111ada9e Mon Sep 17 00:00:00 2001
From: Manuel Gunther <siebenkopf@googlemail.com>
Date: Thu, 23 Feb 2017 19:37:21 -0700
Subject: [PATCH] Implemented check that all configuration file variables are
 consumed (passes also when overwritten on the command line)

---
 bob/bio/base/tools/command_line.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/bob/bio/base/tools/command_line.py b/bob/bio/base/tools/command_line.py
index 7667eb29..31af638b 100644
--- a/bob/bio/base/tools/command_line.py
+++ b/bob/bio/base/tools/command_line.py
@@ -176,6 +176,18 @@ def _take_from_config_or_command_line(args, config, keyword, default, required=T
   elif required:
     raise ValueError("Please specify a %s either on command line (via --%s) or in a configuration file" %(keyword, keyword))
 
+  if config is not None and hasattr(config, keyword):
+    setattr(config, keyword, None)
+
+def _check_config_consumed(config):
+  if config is not None:
+    import inspect
+    for keyword in dir(config):
+      if not keyword.startswith('_') and not keyword.isupper():
+        attr = getattr(config,keyword)
+        if attr is not None and not inspect.isclass(attr) and not inspect.ismodule(attr):
+          logger.warn("The variable '%s' in a configuration file is not known or not supported; use all uppercase variable names (e.g., '%s') to suppress this warning.", keyword, keyword.upper())
+
 
 def initialize(parsers, command_line_parameters = None, skips = []):
   """initialize(parsers, command_line_parameters = None, skips = []) -> args
@@ -279,6 +291,9 @@ def initialize(parsers, command_line_parameters = None, skips = []):
     _take_from_config_or_command_line(args, config, keyword,
         parser.get_default(keyword), required=False, is_resource=False)
 
+  # check that all variables in the config file are consumed by the above options
+  _check_config_consumed(config)
+
   # evaluate skips
   if skips is not None and args.execute_only is not None:
     for skip in skips:
-- 
GitLab