diff --git a/CHANGES.txt b/CHANGES.txt index 90d25f67cae2b55c68ed4de4dda047b7ec7b6ff0..456b8db76105e3fcfaae81aed05930315812cbab 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,11 @@ Global * Changed directory creation to only create parts w/o native variables +Configuration +------------- + +* Changed to allow values with native variables to be interpolated correctly + Release 1.0.9 ============= diff --git a/expconfig.py b/expconfig.py index ed06b15abd99a28f28b60cea56c12e9c17314449..ddd7ccb472e6d24e4d5d589f8c4e012ce279f593 100644 --- a/expconfig.py +++ b/expconfig.py @@ -261,7 +261,23 @@ class ExpConfig(ConfigObj): if isinstance(value, (list, tuple)): value = map(eval_expression, value) elif isinstance(value, basestring): - value = eval_expression(value) + value = eval_expression(value) + if isinstance(value, (list, tuple)): + value = [v.replace('$', '$$') for v in value] + elif isinstance(value, basestring): + value = value.replace('$', '$$') + except (InterpolationError, ValueError) as error: + raise ExpConfigError(error.message, key) + section[key] = value + + # Undo remaining changes from walk with eval_key + def uneval_key(section, key): + try: + value = section[key] + if isinstance(value, (list, tuple)): + value = [v.replace('$$', '$') for v in value] + elif isinstance(value, basestring): + value = value.replace('$$', '$') except (InterpolationError, ValueError) as error: raise ExpConfigError(error.message, key) section[key] = value @@ -454,6 +470,7 @@ class ExpConfig(ConfigObj): config_lines.seek(0) ConfigObj.__init__(self, config_lines, interpolation=False) + self.walk(uneval_key) self.experiment_id = self[ExpConfig.id_name] self.experiment_kind = re.sub(r'-\w+$', '', experiment_type)