22 """Module which defines ConfigOverrides class and related methods. 25 __all__ = [
"ConfigOverrides"]
33 """Defines a set of overrides to be applied to a task config. 35 Overrides for task configuration need to be applied by activator when 36 creating task instances. This class represents an ordered set of such 37 overrides which activator receives from some source (e.g. command line 38 or some other configuration). 42 addFileOverride(filename) 43 Add overrides from a specified file. 44 addValueOverride(field, value) 45 Add override for a specific field. 47 Apply all overrides to a `config` instance. 51 Serialization support for this class may be needed, will add later if 59 """Add overrides from a specified file. 64 Path to the override file. 69 """Add override for a specific field. 71 This method is not very type-safe as it is designed to support 72 use cases where input is given as string, e.g. command line 73 activators. If `value` has a string type and setting of the field 74 fails with `TypeError` the we'll attempt `eval()` the value and 75 set the field with that value instead. 80 Fully-qualified field name. 82 Value to be given to a filed. 87 """Apply all overrides to a task configuration object. 95 `Exception` is raised if operations on configuration object fail. 100 elif otype ==
'value':
101 field, value = override
102 field = field.split(
'.')
105 for attr
in field[:-1]:
106 obj = getattr(obj, attr)
113 if isinstance(value, str)
and obj._fields[field[-1]].dtype
is not str:
116 value = ast.literal_eval(value)
119 raise pexExceptions.RuntimeError(f
"Unable to parse `{value}' into a Python object")
122 setattr(obj, field[-1], value)
def applyTo(self, config)
def addFileOverride(self, filename)
def addValueOverride(self, field, value)