From 0df3d3886296664efb07a5f144abc7ed6f5b5ace Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Thu, 9 Apr 2020 13:11:21 +0300 Subject: [PATCH] Fix self references in configuration when environment variables exist --- trains/utilities/pyhocon/config_parser.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/trains/utilities/pyhocon/config_parser.py b/trains/utilities/pyhocon/config_parser.py index 2efe33d5..b81571ef 100755 --- a/trains/utilities/pyhocon/config_parser.py +++ b/trains/utilities/pyhocon/config_parser.py @@ -89,7 +89,7 @@ class ConfigFactory(object): :param unresolved_value: assigned value value to unresolved substitution. If overriden with a default value, it will replace all unresolved value to the default value. If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by its substitution expression (e.g., ${x}) - :type unresolved_value: boolean + :type unresolved_value: class :return: Config object :type return: Config """ @@ -496,13 +496,20 @@ class ConfigParser(object): _, _, current_item = cls._do_substitute(substitution, value) previous_item = current_item - if len(history) == 1: # special case, when self optional referencing without existing + if len(history) == 1: for substitution in cls._find_substitutions(previous_item): prop_path = ConfigTree.parse_key(substitution.variable) if len(prop_path) > 1 and config.get(substitution.variable, None) is not None: continue # If value is present in latest version, don't do anything if prop_path[0] == key and substitution.optional: cls._do_substitute(substitution, None) + if prop_path[0] == key: + value = os.environ.get(key) + if value is not None: + cls._do_substitute(substitution, value) + continue + if substitution.optional: # special case, when self optional referencing without existing + cls._do_substitute(substitution, None) # traverse config to find all the substitutions @classmethod