mirror of
https://github.com/clearml/clearml
synced 2025-02-07 21:33:25 +00:00
Fix self references in configuration when environment variables exist
This commit is contained in:
parent
3ac7dbdb49
commit
0df3d38862
@ -89,7 +89,7 @@ class ConfigFactory(object):
|
|||||||
:param unresolved_value: assigned value value to unresolved substitution.
|
: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 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})
|
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
|
:return: Config object
|
||||||
:type return: Config
|
:type return: Config
|
||||||
"""
|
"""
|
||||||
@ -496,13 +496,20 @@ class ConfigParser(object):
|
|||||||
_, _, current_item = cls._do_substitute(substitution, value)
|
_, _, current_item = cls._do_substitute(substitution, value)
|
||||||
previous_item = current_item
|
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):
|
for substitution in cls._find_substitutions(previous_item):
|
||||||
prop_path = ConfigTree.parse_key(substitution.variable)
|
prop_path = ConfigTree.parse_key(substitution.variable)
|
||||||
if len(prop_path) > 1 and config.get(substitution.variable, None) is not None:
|
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
|
continue # If value is present in latest version, don't do anything
|
||||||
if prop_path[0] == key and substitution.optional:
|
if prop_path[0] == key and substitution.optional:
|
||||||
cls._do_substitute(substitution, None)
|
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
|
# traverse config to find all the substitutions
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user