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 |
Undocumented |
Constant | IDENTIFIER |
Undocumented |
Function | _format |
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 ... |
Undocumented
Value |
|
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:Any | If this is a string of the format ${expr} , it gets replaced
by the result of JMESPath expression |
formatDict[ | A lookup from string to string with replacement values |
Returns | |
Any | A string formatted according to the format_dict input. |
Raises | |
ValueError | The input data is malformed. |