Skip to content

Commit 88bd28e

Browse files
Update ConfigManagingActor to send a dictionary (#969)
The `ConfigManagingActor` now sends a dictionary instead of the `Config` object. The validation code done through the Config class was ancient without any real purpose. Sending a dictionary is more flexible and allows the user to use the configuration as they see fit. The user can then validate the configuration using marshmallow, pydantic, or any other library. Later, the frequenz-SDK will provide functionality to validate configuration based on the schema provided by the user, still needs to be assessed if it will be done with pydantic, marshmallow, or another library.
2 parents 81ea209 + 858f755 commit 88bd28e

File tree

8 files changed

+8
-381
lines changed

8 files changed

+8
-381
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
This applies to the `ConnectionManager` as well, which also now doesn't expose the `host` and `port` attributes, only the `server_url`. If you need to extract the host or port from the `server_url`, you can use the standard Python `urllib.parse.urlparse()` function.
2222

23+
- The `Config` class was removed and the `ConfigManagingActor` now sends a plain dictionary rather than a `Config` object.
2324

2425
## New Features
2526

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ dependencies = [
3333
"frequenz-channels >= 1.0.0-rc1, < 2.0.0",
3434
"networkx >= 2.8, < 4",
3535
"numpy >= 1.26.4, < 2",
36-
"pydantic >= 2.3, < 3",
3736
"typing_extensions >= 4.6.1, < 5",
3837
]
3938
dynamic = ["version"]

src/frequenz/sdk/actor/_config_managing.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from frequenz.channels.file_watcher import EventType, FileWatcher
1414

1515
from ..actor._actor import Actor
16-
from ..config import Config
1716

1817
_logger = logging.getLogger(__name__)
1918

@@ -33,7 +32,7 @@ class ConfigManagingActor(Actor):
3332
def __init__(
3433
self,
3534
config_path: pathlib.Path | str,
36-
output: Sender[Config],
35+
output: Sender[dict[str, Any]],
3736
event_types: abc.Set[EventType] = frozenset(EventType),
3837
*,
3938
name: str | None = None,
@@ -42,7 +41,7 @@ def __init__(
4241
4342
Args:
4443
config_path: The path to the TOML file with the configuration.
45-
output: The sender to send the config to.
44+
output: The sender to send the configuration to.
4645
event_types: The set of event types to monitor.
4746
name: The name of the actor. If `None`, `str(id(self))` will
4847
be used. This is used mostly for debugging purposes.
@@ -59,7 +58,7 @@ def __init__(
5958
self._file_watcher: FileWatcher = FileWatcher(
6059
paths=[self._config_path.parent], event_types=event_types
6160
)
62-
self._output: Sender[Config] = output
61+
self._output: Sender[dict[str, Any]] = output
6362

6463
def _read_config(self) -> dict[str, Any]:
6564
"""Read the contents of the configuration file.
@@ -79,8 +78,7 @@ def _read_config(self) -> dict[str, Any]:
7978

8079
async def send_config(self) -> None:
8180
"""Send the configuration to the output sender."""
82-
conf_vars = self._read_config()
83-
config = Config(conf_vars)
81+
config = self._read_config()
8482
await self._output.send(config)
8583

8684
async def _run(self) -> None:

src/frequenz/sdk/config/__init__.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/frequenz/sdk/config/_config.py

Lines changed: 0 additions & 167 deletions
This file was deleted.

tests/actor/test_config_manager.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33

44
"""Test for ConfigManager."""
55
import pathlib
6+
from typing import Any
67

78
import pytest
89
from frequenz.channels import Broadcast
9-
from pydantic import BaseModel
1010

1111
from frequenz.sdk.actor import ConfigManagingActor
12-
from frequenz.sdk.config import Config
1312

1413

15-
class Item(BaseModel):
14+
class Item:
1615
"""Test item."""
1716

1817
item_id: int
@@ -76,7 +75,7 @@ async def test_update(self, config_file: pathlib.Path) -> None:
7675
- the initial content of the content file is correct
7776
- the config file modifications are picked up and the new content is correct
7877
"""
79-
config_channel: Broadcast[Config] = Broadcast(
78+
config_channel: Broadcast[dict[str, Any]] = Broadcast(
8079
name="Config Channel", resend_latest=True
8180
)
8281
config_receiver = config_channel.new_receiver()

tests/config/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)