15 Moe and the derived modules use many configuration variables indicating i.e. working directories,
16 task name, compiler commandline and options, current test name and name of test file to use.
17 All values are treated as text and may contain unicode characters (although this is usually not advisable).
18 A variable may be either set to a simple fixed string or to a string containing expansions of other variables.
19 The configuration library also supports appending text, conditionals and a simple variable hierarchy.
21 For the complete configuration syntax grammar, see :mod:`moe.config_parser` documentation.
23 Generally, both whitespace and indentation are optional and do not matter, individual
24 operations must be separated by either ``;`` or newline, ``#`` introduces a comment until the end of the line.
26 In *moe*, the config files are assumed to be in UTF-8, but using non-ASCII characters are discouraged outside
27 comments (mainly because not all unix comands handle unicode well).
29 Variables and substitution
30 ^^^^^^^^^^^^^^^^^^^^^^^^^^
32 The names of the variables may consist of letters, numbers, underscore, dash and a dot. Dot acts as
33 a separator of the variable name hierarchy and may not occur at the beginning or the end of variable name,
34 nor adjacent to another dot. The tree hierarchy is provided only for user's convenience and does not play
35 any significant role in variable evaluation.
37 The value of a variable may be defined by several operations:
39 **SET**, ``VAR = "value"``
40 Sets the variable to the variable-expansion of the string.
42 **APPEND**, ``VAR += "value"``
43 Appends the variable-expansion of the string.
45 Value is a ``"``-delimited string that may contain substitutions in the form ``{VARNAME}`` i.e.
46 ``"source-{VERSION}.{SUFFIX}"``, where ``VERSION`` and ``SUFFIX`` are the substituted variables.
47 The string may contain any characters including unicode (although this is not always advisable).
48 Characters ``"``, ``{``, ``{`` and ``\`` have to be escaped with ``\``, i.e. ``\"``, ``\{``, ``\{`` and ``\\``.
50 When evaluating a variable, all the substitutions are evaluated as well. Every variable is evaluated
51 in the same way, independently of the priority of the operations it occurs in. The substitutions must
52 therefore be acyclic and a variable may not contain itself as a substitution.
58 Each operation has a priority usually depending on its origin, i.e. builtins, global config file, task config file
59 or commandline overrides.
60 Only the **SET** operation with the highest priority and higher priority **APPENDs** are used (as if all operations were
61 applied from the least priority operation to the highest).
62 Operations of the same priority are processed by their definition order (first to last).
64 For example, in builtins (priority 0) we may have::
66 COMPILE = "{CC} {OPTS} {INFILE} -o {OUTFILE}"
70 In config file (priority 30)::
72 OPTS += " -W{WARNOPT}" # OPTS is now "-O{OPTIMIZE} -W{WARNOPT}"
76 And in command-line overrides (priority 100)::
78 COMPILE = "cp {INFILE} {OUTFILE}"
80 Moe would then later set ``INFILE`` and ``OUTFILE`` at some point before evaluating and executing
81 the compilation command.
83 With these *lazy* semantics, it is possible to set a variable to a value depending
84 on both higher- and lower-priority operations.
87 The implementation is actually very efficient and recalculates only the necessary values,
88 caching the results. Adding/removing operations to variables only recursively invalidates the
89 (potentially) influenced cached values, these are recalculated lazily on-demand.
95 The variables form a tree-like hierarchy with levels separated by dots. The variables
96 may be defined either by providing the full name or by inside subtrees.
97 Subtrees provide all the *defined* variables with given dot-separated prefix.
98 Substituted variable names must be given by their full names. ::
103 # Defines LOG.VERBOSE
104 TEST.LOGFILE = "{LOG.DIR}/test.log"
105 # Defines LOG.TEST.LOGFILE
107 LOG.TEST { VERBOSE = "Y" }
108 # The subtree name may contain several level names
113 Any block of operations may be guarded by a condition. The conditions may be nested and
114 consist of expressions containing ``and``, ``or``, ``not`` and variable/string (in)equalities. The strings
115 may contain substitutions.
117 The syntax is the following::
119 if (NAME == "{TASK}.cc") or (NAME == "{TASK}.cpp") or
120 ((LANG_HINT == "C") and (not FOO != "BAR"))
125 The curly brackets delimiting the bloc, as well as the brackets in the boolena expression,
126 are mandatory. ``else`` is not supported. ``if VAR=="FOO" {...}`` is equivalent to ``if "{VAR}"=="FOO" {...}``.
132 .. highlight:: python
133 .. automodule:: moe.config
138 .. autoclass:: ConfigError
139 .. autoclass:: UndefinedError
140 .. autoclass:: VariableNameError
141 .. autoclass:: VariableFixedError
142 .. autoclass:: CyclicConfigError
147 The configuration environment :class:`ConfigTree` is implemented as a flat dictionary of variables
148 referenced by their full name.
150 .. autoclass:: ConfigTree
156 Every variable object :class:`ConfigVar` stores the list of its defining operations, the current
157 cached value and both the variables its current value depends on and the variables that currently depend on it.
158 All the dependencies are calculated upon evaluation and removed upon invalidation.
159 Only the operations and conditions influencing the current value contribute to dependencies.
161 .. note:: If no **SET** applies, a variable is still undefined even if some **APPEND** applies. This *might* change.
163 .. autoclass:: ConfigVar
169 Every operation object is either **SET** or **APPEND** and may be guarded by a
172 .. autoclass:: Operation
177 Every condition is defined by a formula, the result is cached in the same way as with :class:`ConfigVar`, including
178 dependency tracking. A condition may depend on another parent condition in case this condition is
179 nested inside another. In this case the parent condition is checked first and the parent condition is a dependency.
181 .. autoclass:: ConfigCondition
187 .. autoclass:: ConfigElem
190 .. autoclass:: ConfigExpression
194 ----------------------------------------
195 Config parser module `moe.config_parser`
196 ----------------------------------------
198 .. automodule:: moe.config_parser