utils
Attributes#
Classes#
ConfigError #
Bases: Exception
Overrideable #
Bases: YamlModel
, GenericModel
, Generic[Config]
Attributes#
overrides
class-attribute
instance-attribute
#
overrides: Dict[str, Any] = Field(
default_factory=dict,
description="Overrides to apply to the config file referenced by `path`.\nOverrides are defined in `key`: `value` pairs, where the `key` is a pointer to the object in the config file to override and the `value` is what should replace it.\nThe format of the keys is a cross between path-like structures and a python dictionary. For example, to change the 'location_id' property on the python object `obj = {'attrs': {'location_id': 'abc'}, 'data_vars': {...}}` to 'sgp' you would write `/attrs/location_id: 'sgp'`.\nOverrides are implemented using https://python-json-pointer.readthedocs.io/en/latest/tutorial.html",
)
path
class-attribute
instance-attribute
#
path: FilePath = Field(
description="Path to the configuration file to borrow configurations from.\nNote that this path is relative to the project root, so you should include any paths in between the project root and your config file.\nE.g., `pipelines/lidar/config/dataset.yaml`"
)
ParameterizedConfigClass #
Bases: BaseModel
Attributes#
classname
class-attribute
instance-attribute
#
classname: StrictStr = Field(
description="The import path to the Python class that should be used, e.g., if your import statement looks like `from foo.bar import Baz`, then your classname would be `foo.bar.Baz`."
)
parameters
class-attribute
instance-attribute
#
parameters: Dict[str, Any] = Field(
{},
description="Optional dictionary that will be passed to the Python class specified by 'classname' when it is instantiated. If the object is a tsdat class, then the parameters will typically be made accessible under the `params` property on an instance of the class. See the documentation for individual classes for more information.",
)
Functions#
classname_looks_like_a_module
classmethod
#
Source code in tsdat/config/utils.py
instantiate #
Instantiates and returns the class specified by the 'classname' parameter.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
An instance of the specified class. |
Source code in tsdat/config/utils.py
YamlModel #
Bases: BaseModel
Functions#
from_yaml
classmethod
#
Creates a python configuration object from a yaml file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
Path
|
The path to the yaml file |
required |
overrides |
Optional[Dict[str, Any]]
|
Overrides to apply to the yaml before instantiating the YamlModel object. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
YamlModel |
A YamlModel subclass |
Source code in tsdat/config/utils.py
generate_schema
classmethod
#
Generates JSON schema from the model fields and type annotations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_file |
Path
|
The path to store the JSON schema. |
required |
Source code in tsdat/config/utils.py
Functions#
find_duplicates #
Source code in tsdat/config/utils.py
get_code_version #
Source code in tsdat/config/utils.py
matches_overrideable_schema #
read_yaml #
recursive_instantiate #
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:
Name | Type | Description | Default |
---|---|---|---|
model |
Any
|
The object to recursively instantiate. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The recursively-instantiated object. |