tsdat.config.utils
Classes
Abstract base class for generic types. |
|
Functions
Instantiates all ParametrizedClass components and subcomponents of a given model. |
Function Descriptions
- exception tsdat.config.utils.ConfigError[source]
Bases:
Exception
Common base class for all non-exit exceptions.
Initialize self. See help(type(self)) for accurate signature.
- class tsdat.config.utils.Overrideable[source]
Bases:
YamlModel
,pydantic.generics.GenericModel
,Generic
[Config
]Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows:
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default
- class tsdat.config.utils.ParameterizedConfigClass[source]
Bases:
pydantic.BaseModel
Class Methods
Instantiates and returns the class specified by the 'classname' parameter.
Method Descriptions
- class tsdat.config.utils.YamlModel[source]
Bases:
pydantic.BaseModel
Class Methods
Creates a python configuration object from a yaml file.
Generates JSON schema from the model fields and type annotations.
Method Descriptions
- classmethod from_yaml(filepath: pathlib.Path, overrides: Dict[str, Any] | None = None)[source]
Creates a python configuration object from a yaml file.
- Parameters:
filepath (Path) – The path to the yaml file
overrides (Optional[Dict[str, Any]], optional) – Overrides to apply to the yaml before instantiating the YamlModel object. Defaults to None.
- Returns:
YamlModel – A YamlModel subclass
- tsdat.config.utils.recursive_instantiate(model: Any) Any [source]
Instantiates all ParametrizedClass components and subcomponents of a given model.
Recursively calls model.instantiate() on all ParameterizedConfigClass instances under the the model, resulting in a new model which follows the same general structure as the given model, but possibly containing totally different properties and methods.
Note that this method does a depth-first traversal of the model tree to to instantiate leaf nodes first. Traversing breadth-first would result in new pydantic models attempting to call the __init__ method of child models, which is not valid because the child models are ParameterizedConfigClass instances. Traversing depth-first allows us to first transform child models into the appropriate type using the classname of the ParameterizedConfigClass.
This method is primarily used to instantiate a Pipeline subclass and all of its properties from a yaml pipeline config file, but it can be applied to any other pydantic model.
- Parameters:
model (Any) – The object to recursively instantiate.
- Returns:
Any – The recursively-instantiated object.