Skip to content

Commit e03305d

Browse files
committed
Add a base config schema that provides quantities support
This schema is provided to use as a default, and might be extended in the future to support more commonly used fields that are not provided by marshmallow by default. To use the quantity schema we need to bump the `frequenz-quantities` dependency and add the optional `marshmallow` dependency. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 3e8b47c commit e03305d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies = [
3131
# (plugins.mkdocstrings.handlers.python.import)
3232
"frequenz-client-microgrid >= 0.6.0, < 0.7.0",
3333
"frequenz-channels >= 1.4.0, < 2.0.0",
34-
"frequenz-quantities >= 1.0.0rc3, < 2.0.0",
34+
"frequenz-quantities[marshmallow] >= 1.0.0, < 2.0.0",
3535
"networkx >= 2.8, < 4",
3636
"numpy >= 1.26.4, < 2",
3737
"typing_extensions >= 4.6.1, < 5",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# License: MIT
2+
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Base schema for configuration classes."""
5+
6+
from frequenz.quantities.experimental.marshmallow import QuantitySchema
7+
8+
9+
class BaseConfigSchema(QuantitySchema):
10+
"""A base schema for configuration classes."""

src/frequenz/sdk/config/_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing_extensions import override
1717

1818
from ..actor._background_service import BackgroundService
19+
from ._base_schema import BaseConfigSchema
1920
from ._managing_actor import ConfigManagingActor
2021
from ._util import DataclassT, load_config
2122

@@ -139,7 +140,7 @@ def new_receiver( # pylint: disable=too-many-arguments
139140
/,
140141
*,
141142
skip_unchanged: bool = True,
142-
base_schema: type[Schema] | None = None,
143+
base_schema: type[Schema] | None = BaseConfigSchema,
143144
marshmallow_load_kwargs: dict[str, Any] | None = None,
144145
) -> Receiver[DataclassT | Exception | None]:
145146
"""Create a new receiver for receiving the configuration for a particular key.
@@ -388,7 +389,7 @@ def _load_config(
388389
config_class: type[DataclassT],
389390
*,
390391
key: str | Sequence[str],
391-
base_schema: type[Schema] | None = None,
392+
base_schema: type[Schema] | None = BaseConfigSchema,
392393
marshmallow_load_kwargs: dict[str, Any] | None = None,
393394
) -> DataclassT | InvalidValueForKeyError | ValidationError | None:
394395
"""Try to load a configuration and log any validation errors."""

0 commit comments

Comments
 (0)