tsdat.config.utils

Classes

Overrideable

Abstract base class for generic types.

ParameterizedConfigClass

YamlModel

Functions

get_code_version

read_yaml

recursive_instantiate

Instantiates all ParametrizedClass components and subcomponents of a given model.

Function Descriptions

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
overrides :Dict[str, Any][source]
path :pydantic.FilePath[source]
class tsdat.config.utils.ParameterizedConfigClass[source]

Bases: pydantic.BaseModel

classname :pydantic.StrictStr[source]
parameters :Dict[str, Any][source]

Class Methods

classname_looks_like_a_module

instantiate

Instantiates and returns the class specified by the 'classname' parameter.

Method Descriptions

classmethod classname_looks_like_a_module(cls, v: pydantic.StrictStr) pydantic.StrictStr[source]
instantiate(self) Any[source]

Instantiates and returns the class specified by the ‘classname’ parameter.

Returns

Any – An instance of the specified class.

class tsdat.config.utils.YamlModel[source]

Bases: pydantic.BaseModel

Class Methods

from_yaml

Creates a python configuration object from a yaml file.

generate_schema

Generates JSON schema from the model fields and type annotations.

Method Descriptions

classmethod from_yaml(cls, filepath: pathlib.Path, overrides: Optional[Dict[str, Any]] = 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

classmethod generate_schema(cls, output_file: pathlib.Path)[source]

Generates JSON schema from the model fields and type annotations.

Parameters

output_file (Path) – The path to store the JSON schema.

tsdat.config.utils.get_code_version() str[source]
tsdat.config.utils.read_yaml(filepath: pathlib.Path) Dict[Any, Any][source]
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.