climate_ref._config_helpers
#
config(maybe_cls=None, *, prefix, frozen=False)
#
Make a class a configuration class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
The prefix that is used for the env variables. This is be prepended to all the fields that use an |
required |
frozen
|
bool
|
The configuration will be immutable after instantiation, if |
False
|
Source code in packages/climate-ref/src/climate_ref/_config_helpers.py
env_field(name, **kwargs)
#
Create a field with an environment variable override.
This field will use a value from the environment if it is set.
This field requires the class to be decorated with config to work.
The environment variable name is constructed by prefixing the field name with the class prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the environment variable to use without a prefix |
required |
kwargs
|
Any
|
Additional arguments to pass to the field |
{}
|
Returns:
| Type | Description |
|---|---|
field
|
The field with the environment variable override |
Source code in packages/climate-ref/src/climate_ref/_config_helpers.py
transform_error(exc, path='$', format_exception=_format_exception)
#
Transform an exception into a list of error messages.
This is based on cattrs.transform_error, but modified to be able to ignore errors
To get detailed error messages, the exception should be produced by a converter
with detailed_validation set.
By default, the error messages are in the form of {description} @ {path}.
While traversing the exception and subexceptions, the path is formed:
- by appending
.{field_name}for fields in classes - by appending
[{int}]for indices in iterables, like lists - by appending
[{str}]for keys in mappings, like dictionaries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
ClassValidationError | IterableValidationError | BaseException
|
The exception to transform into error messages. |
required |
path
|
str
|
The root path to use. |
'$'
|
format_exception
|
Callable[[BaseException, type | None], str | None]
|
A callable to use to transform |
_format_exception
|