utils
Utility functions related to config YAML specification classes.
Module
Functions
get_pydash_deep_paths
def get_pydash_deep_paths(obj: _JSON) ‑> dict[str, str | int | float | bool | None]:
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[marshmallow.schema.Schema]:
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.