utils
Utility functions related to config YAML specification classes.
Module
Functions
get_pydash_deep_paths
def get_pydash_deep_paths(obj: _JSON) ‑> dict:
Produce a map of pydash deep path strings to values for a given JSON object.
Output keys will be deep path strings per https://pydash.readthedocs.io/en/stable/deeppath.html.
keep_desert_output_as_dict
def keep_desert_output_as_dict(clazz: type[marshmallow.Schema]) ‑> type:
Make a desert schema deserialize as a dict.
Normally desert
will deserialize back into the dataclass that was used to
generate the schema in the first place. However, there are times when we want to
specify the schema via a dataclass (for simplicity), but use the schema as a
dict. We could simply call asdict()
on the deserialized dataclass but if the
instance is nested deep within an object this may be tricky or not preferable.
This function works by modifying the registered hooks on the schema class to
remove the "make_data_class" post_load
hook that desert
has added.
replace_template_variables
def replace_template_variables( config: _JSON, replace_map: dict[str, _JSON], error_on_absence: bool = False,) ‑> dict[str, '_JSON'] | list['_JSON'] | str | int | float | bool | None:
Replace template variables in a JSON object with intended replacements.
Only replaces template variables which are values within the (nested) JSON object, not keys, etc.
replace_templated_variables
def replace_templated_variables( config_dict: dict[str, Any], template_params: Optional[dict[str, Any]] = None,) ‑> dict:
Replace templated variables in a task config.
This function checks if a config has a 'template' section and automatically
replaces template variables (like {{ variable_name }}
) with ones supplied
in the template_params
argument. If not supplied, the default values
from the template configuration are used instead.
Arguments
config_dict
: The configuration dictionary containing template variablestemplate_params
: Optional dictionary mapping template parameter names to values. These take precedence over default values.
Returns The configuration dictionary with template variables replaced by defaults
Raises
ValueError
: If a template variable has no default value and no template param