Skip to content

Commit adde8c2

Browse files
authored
Upgrade client-base to v0.2.0 (#20)
- **Bump mkdocs-material from 9.5.11 to 9.5.12** - **Upgrade `client-base` to v0.2.0** - **Rename `retry_spec` to `retry_strategy`**
2 parents b8aa419 + 150099c commit adde8c2

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ Code import from the [SDK v1.0.0-rc5](https://github.com/frequenz-floss/frequenz
99
Changes compared to the code in the SDK v1.0.0-rc5 release:
1010

1111
* The `MicrogridGrpcClient` class was renamed to `ApiClient`.
12+
13+
* The `retry_spec` constructor argument was renamed to `retry_strategy`.
14+
1215
* The `MicrogridApiClient` abstract base class was removed, use `ApiClient` instead.
16+
1317
* The `Connection` class is now a `dataclass` instead of a `NamedTuple`. If you use the tuple-like interface (`connection[0]`, etc.) you should use the named attributes instead or use [`dataclasses.astuple()`](https://docs.python.org/3/library/dataclasses.html#dataclasses.astuple) to convert it to a tuple.

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ plugins:
118118
- https://frequenz-floss.github.io/frequenz-api-common/v0.5/objects.inv
119119
- https://frequenz-floss.github.io/frequenz-api-microgrid/v0.15/objects.inv
120120
- https://frequenz-floss.github.io/frequenz-channels-python/v1.0-pre/objects.inv
121-
- https://frequenz-floss.github.io/frequenz-client-base-python/v0.2-dev/objects.inv
121+
- https://frequenz-floss.github.io/frequenz-client-base-python/v0.2/objects.inv
122122
- https://grpc.github.io/grpc/python/objects.inv
123123
- https://typing-extensions.readthedocs.io/en/stable/objects.inv
124124
# Note this plugin must be loaded after mkdocstrings to be able to use macros

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ requires-python = ">= 3.11, < 4"
3838
dependencies = [
3939
"frequenz-api-microgrid >= 0.15.3, < 0.16.0",
4040
"frequenz-channels == 1.0.0b2",
41-
"frequenz-client-base @ git+https://github.com/frequenz-floss/frequenz-client-base-python.git@03f2ed2104efc1bdad05eed68db167e87eb8b1aa",
41+
"frequenz-client-base >= 0.2.0, < 0.3.0",
4242
"grpcio >= 1.54.2, < 2",
4343
"protobuf >= 4.25.3, < 5",
4444
"timezonefinder >= 6.2.0, < 7",
@@ -66,7 +66,7 @@ dev-mkdocs = [
6666
"mkdocs-gen-files == 0.5.0",
6767
"mkdocs-literate-nav == 0.6.1",
6868
"mkdocs-macros-plugin == 1.0.5",
69-
"mkdocs-material == 9.5.11",
69+
"mkdocs-material == 9.5.12",
7070
"mkdocstrings[python] == 0.24.1",
7171
"frequenz-repo-config[lib] == 0.9.1",
7272
]

src/frequenz/client/microgrid/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
"""
88

99

10-
from frequenz.client.base.retry_strategy import (
11-
ExponentialBackoff,
12-
LinearBackoff,
13-
RetryStrategy,
14-
)
15-
1610
from ._client import ApiClient
1711
from ._component import Component
1812
from ._component_data import (
@@ -35,11 +29,8 @@
3529
"EVChargerCableState",
3630
"EVChargerComponentState",
3731
"EVChargerData",
38-
"ExponentialBackoff",
3932
"InverterData",
40-
"LinearBackoff",
4133
"Location",
4234
"Metadata",
4335
"MeterData",
44-
"RetryStrategy",
4536
]

src/frequenz/client/microgrid/_client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030

3131
# pylint: enable=no-name-in-module
3232
from frequenz.channels import Receiver
33-
from frequenz.client.base.grpc_streaming_helper import GrpcStreamingHelper
34-
from frequenz.client.base.retry_strategy import LinearBackoff, RetryStrategy
33+
from frequenz.client.base import retry, streaming
3534
from google.protobuf.empty_pb2 import Empty # pylint: disable=no-name-in-module
3635

3736
from ._component import (
@@ -68,25 +67,25 @@ def __init__(
6867
self,
6968
grpc_channel: grpc.aio.Channel,
7069
target: str,
71-
retry_spec: RetryStrategy = LinearBackoff(),
70+
retry_strategy: retry.Strategy = retry.LinearBackoff(),
7271
) -> None:
7372
"""Initialize the class instance.
7473
7574
Args:
7675
grpc_channel: asyncio-supporting gRPC channel
7776
target: server (host:port) to be used for asyncio-supporting gRPC
7877
channel that the client should use to contact the API
79-
retry_spec: Specs on how to retry if the connection to a streaming
80-
method gets lost.
78+
retry_strategy: The retry strategy to use to reconnect when the connection
79+
to the streaming method is lost.
8180
"""
8281
self.target = target
8382
"""The location (as "host:port") of the microgrid API gRPC server."""
8483

8584
self.api = MicrogridStub(grpc_channel)
8685
"""The gRPC stub for the microgrid API."""
8786

88-
self._broadcasters: dict[int, GrpcStreamingHelper[Any, Any]] = {}
89-
self._retry_spec = retry_spec
87+
self._broadcasters: dict[int, streaming.GrpcStreamBroadcaster[Any, Any]] = {}
88+
self._retry_strategy = retry_strategy
9089

9190
async def components(self) -> Iterable[Component]:
9291
"""Fetch all the components present in the microgrid.
@@ -264,7 +263,7 @@ async def _new_component_data_receiver(
264263

265264
broadcaster = self._broadcasters.setdefault(
266265
component_id,
267-
GrpcStreamingHelper(
266+
streaming.GrpcStreamBroadcaster(
268267
f"raw-component-data-{component_id}",
269268
# We need to cast here because grpc says StreamComponentData is
270269
# a grpc.CallIterator[PbComponentData], not a

tests/test_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
from frequenz.api.microgrid.microgrid_pb2 import ConnectionFilter as PbConnectionFilter
1919
from frequenz.api.microgrid.microgrid_pb2 import ConnectionList as PbConnectionList
2020
from frequenz.api.microgrid.microgrid_pb2 import SetBoundsParam as PbSetBoundsParam
21-
from frequenz.client.base.retry_strategy import LinearBackoff
22-
from google.protobuf.empty_pb2 import Empty
2321

2422
# pylint: enable=no-name-in-module
23+
from frequenz.client.base.retry import LinearBackoff
24+
from google.protobuf.empty_pb2 import Empty # pylint: disable=no-name-in-module
25+
2526
from frequenz.client.microgrid import _client as client
2627
from frequenz.client.microgrid._component import (
2728
Component,
@@ -66,7 +67,7 @@ async def _gprc_server(
6667
microgrid = client.ApiClient(
6768
grpc.aio.insecure_channel(f"[::]:{port}"),
6869
f"[::]:{port}",
69-
retry_spec=LinearBackoff(interval=0.0, jitter=0.05),
70+
retry_strategy=LinearBackoff(interval=0.0, jitter=0.05),
7071
)
7172
await server.start()
7273
try:

0 commit comments

Comments
 (0)