module documentation

This module provides kedro.config with the functionality to load one or more configuration files from specified paths, and format template strings with the values from the passed dictionary.

Constant FULL_STRING_IDENTIFIER_PATTERN Undocumented
Constant IDENTIFIER_PATTERN Undocumented
Function _format_object Recursive function that loops through the values of a map. In case another map or a list is encountered, it calls itself. When a string is encountered, it will use the format_dict to replace strings that look like ...
FULL_STRING_IDENTIFIER_PATTERN = (source)

Undocumented

Value
re.compile(('^'+IDENTIFIER_PATTERN.pattern)+'$', re.VERBOSE)
IDENTIFIER_PATTERN = (source)

Undocumented

Value
re.compile('''\\$\\{
    (?P<path>[A-Za-z0-9_\\.]+)  # identifier
    (?:\\|(?P<default>[^}]*))?  # optional default value
    \\}''',
           re.VERBOSE)
def _format_object(val: Any, format_dict: Dict[str, Any]) -> Any: (source)

Recursive function that loops through the values of a map. In case another map or a list is encountered, it calls itself. When a string is encountered, it will use the format_dict to replace strings that look like ${expr}, where expr is a JMESPath expression evaluated against format_dict.

Some notes on behavior:
  • If val is not a dict, list or string, the same value gets passed back.
  • If val is a string and does not match the ${...} pattern, the same
    value gets passed back.
  • If the value inside ${...} does not match any keys in the dictionary,
    the error is raised, unless a default is provided.
  • If the default is provided with ${...|default}, and the key is not
    found in the dictionary, the default value gets passed back.
  • If the ${...} is part of a larger string, the corresponding entry in
    the format_dict gets parsed into a string and put into the larger string.

Examples

val = "${test_key}" with format_dict = {'test_key': 'test_val'} returns
'test_val'

val = 5 (i.e. not a dict, list or string) returns 5 val = "test_key" (i.e. does not match ${...} pattern returns 'test_key'

(irrespective of format_dict)
val = "${wrong_test_key}" with format_dict = {'test_key': 'test_val'}
raises ValueError
val = "string-with-${test_key}" with format_dict = {'test_key': 1000}
returns "string-with-1000"
val = "${wrong_test_key|default_value}" with format_dict = {}
returns 'default_value'
Parameters
val:AnyIf this is a string of the format ${expr}, it gets replaced by the result of JMESPath expression
format_dict:Dict[str, Any]A lookup from string to string with replacement values
Returns
AnyA string formatted according to the format_dict input.
Raises
ValueErrorThe input data is malformed.