]> mj.ucw.cz Git - moe.git/blobdiff - t/moe/config.py
Pipeline functions now get keyword arguments
[moe.git] / t / moe / config.py
index f24e1ef8f357748b41b13f2b8cff20419cfb90d7..dacaf42a7a1450e45fa505c266cb7fecc1b01e1d 100644 (file)
@@ -1,10 +1,6 @@
 """
-config.py
----------
-
 Lazy conditional string evaluation module for Moe configuration variables.
 
-
 * Each variable has ordered list of operations (definitions), each defining operation either 
   assigns (SET) or appends (APPEND) value of an expression to the variable. Each operation may be guarded by condition(s). 
 
@@ -98,19 +94,26 @@ class ConfigTree(object):
       self.variables[k].dump(prefix) for k in sorted(self.variables.keys())
       ])
 
+  def fix(self, keys):
+    "Fix value of variable or list of variables. Fixing undefined variable raises `UndefinedError`."
+    if isinstance(keys, types.StringTypes):
+      keys = [keys]
+    for key in keys:
+      self.lookup(key, create=True).fix()
+
   def parse(self, s, source=None, level=0):
     """Parse `s` (stream/string) into the tree, see `moe.confparser.ConfigParser` for details."""
-    import moe.confparser
-    p = moe.confparser.ConfigParser(text, self, source=source, level=level)
+    import moe.config_parser
+    p = moe.config_parser.ConfigParser(s, self, source=source, level=level)
     p.parse()
 
   def parse_file(self, filename, desc=None, level=0):
     """Parse an utf-8 file into the tree, see `moe.confparser.ConfigParser` for details. 
     Names the source "`filename` <`desc`>". """
-    f = open(filename, 'rt')
-    if desc: 
-      filename += " <" + desc + ">" 
-    self.parse(f, source=filename, level=level)
+    with open(filename, 'rt') as f:
+      if desc: 
+       filename += " <" + desc + ">" 
+      self.parse(f, source=filename, level=level)
 
 
 class ConfigElem(object):
@@ -278,14 +281,14 @@ class ConfigVar(ConfigElem):
     self.fixed = True
 
   def unfix(self):
-    "Set the variable to be modifiable again."
+    "Make the variable modifiable again."
     self.fixed = False
 
   def value(self, depth=0):
     "Handle the case when fixed, raise exc. on different evaluation"
     val = super(ConfigVar,self).value(depth)
     if self.fixed and self.fixed_val != val:
-      raise VariableFixedError("value of var %s was fixed to %r but evaluated to %r", self.name, self.fixed_val, val)
+      raise VariableFixedError("value of var %r was fixed to %r but evaluated to %r", self.name, self.fixed_val, val)
     return val
 
   def add_operation(self, operation):