-
Couldn't load subscription status.
- Fork 20
Improve Actors documentation #689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I have a couple of TODOs:
|
0525561 to
da7192b
Compare
|
This is based on #688. |
The merge-base changed after approval.
f372cea to
1ad1f67
Compare
|
Rebased on the current v0.x.x and added a few improvements:
They are all new commits so it should be easy to resume the reviewing 😇 |
|
Enabled auto-merge. |
ab6d1ea to
0c2d276
Compare
|
Mmm, there is an unrelated test failure now, I guess |
|
But this is already checked by mypy, pylint has an incomplete implementation that doesn't look at type hints. We see the same failure where it is checking the generated grpc code in the api client implementation as well. We should just disable the check for the whole of the sdk. But adding some constraints in the code doesn't sound like a bad idea either: diff --git a/src/frequenz/sdk/microgrid/_data_pipeline.py b/src/frequenz/sdk/microgrid/_data_pipeline.py
index 09f5808c..a5483e2a 100644
--- a/src/frequenz/sdk/microgrid/_data_pipeline.py
+++ b/src/frequenz/sdk/microgrid/_data_pipeline.py
@@ -30,6 +30,7 @@ _logger = logging.getLogger(__name__)
# pylint: disable=import-outside-toplevel
if typing.TYPE_CHECKING:
from ..actor import (
+ Actor,
ComponentMetricRequest,
ComponentMetricsResamplingActor,
DataSourcingActor,
@@ -52,7 +53,8 @@ A larger buffer size means that the DataSourcing and Resampling actors don't dro
requests and will be able to keep up with higher request rates in larger installations.
"""
-_T = typing.TypeVar("_T")
+_T = typing.TypeVar("_T", bound="Actor")
"""Type variable for generic actor types."""
|
Signed-off-by: Leandro Lucarella <[email protected]>
It is much easier to find all the available members of a class if the inherited members are shown, otherwise one have to inpect every base manually. Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
These new sections explain in more detail how actors work, and what's needed to both use them and implement them properly. Signed-off-by: Leandro Lucarella <[email protected]>
Also add the expected output for the example. Signed-off-by: Leandro Lucarella <[email protected]>
This illustrates the use of select to be able to manage multiple channels in one actor. It also showcases a bit more the `run()` function and more advance uses of channels. Signed-off-by: Leandro Lucarella <[email protected]>
This section explains how to use the underlaying `BackgroundService` to spawn new tasks and get them automatically cancelled when stopping the actor. Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
The SDK doesn't enforce the use of channels, but it's the recommended way to communicate between actors and the one used by SDK actors. Signed-off-by: Leandro Lucarella <[email protected]>
Now when talking about the `Actor` class, a link to the class is used more consistently. When mentioning the `_run()` method, a link to the "The `_run()` Method" section is provided too. When mentioning frequenz channels, we link using the module instead of using URL. This improves consistency but also makes sure we link to the version the SDK is currently using. Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
The detailed documentation for how to use and implement actors now lives in the module. The class documentation is removed because it is not comprehensive enough and to avoid duplication. A link to the module documentation will be added in a separate commit. Signed-off-by: Leandro Lucarella <[email protected]>
To be able to use the `Actor` class and `run()` function there is a lot to have in mind that is hard to explain (without a lot of duplication) in each docstring. Because of this we just add an information box suggesting users to read the module-level documentation. Signed-off-by: Leandro Lucarella <[email protected]>
The initializer is not trivial, as it is usually the one taking input and output channels, and the `Actor.__init__()` needs to be called too, and the optional `name` should be explained too. The new section includes an example and a continuation of this example is added to the "The `_run()` Method" section, to make it more clear what the bare minimum needed to implement a complete actor. We also add the `name` argument to the complete examples. Signed-off-by: Leandro Lucarella <[email protected]>
The `nox` job makes `publish-docs` depend on every `nox` job matrix entry, while the `nox-all` is a join point for them. Depending on both has the same effect, but the dependency graph looks nicer if we depend on `nox-all` instead. Signed-off-by: Leandro Lucarella <[email protected]>
|
Merging without the queue because of the flakiness. |
actormodule documentation)