Skip to content

Commit d2eea99

Browse files
committed
Fix and complete documentation for grpc_tools
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 7cd596f commit d2eea99

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/frequenz/repo/config/setuptools/grpc_tools.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# License: MIT
22
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
33

4-
"""Setuptool hooks to build protobuf files."""
4+
"""Setuptool hooks to build protobuf files.
55
6+
This module provides a function that returns a dictionary with the required
7+
machinery to build protobuf files via setuptools.
8+
"""
69

710
import pathlib
811
import subprocess
@@ -22,6 +25,22 @@ def build_proto_cmdclass(
2225
) -> dict[str, Any]:
2326
"""Return a dictionary with the required machinery to build protobuf files.
2427
28+
This dictionary is meant to be passed as the `cmdclass` argument of
29+
`setuptools.setup()`.
30+
31+
It will add the following commands to setuptools:
32+
33+
- `compile_proto`: Adds a command to compile the protobuf files to
34+
Python files.
35+
- `build_py`: Use the `compile_proto` command to build the python files
36+
and run the regular `build_py` command, so the protobuf files are
37+
create automatically when the python package is created.
38+
39+
Unless an explicit `include_paths` is passed, the
40+
`submodules/api-common-protos` wiil be added to the include paths, so your
41+
project should have a submodule with the common google api protos in that
42+
path.
43+
2544
Args:
2645
proto_path: Path of the root directory containing the protobuf files.
2746
proto_glob: The glob pattern to use to find the protobuf files.
@@ -30,28 +49,16 @@ def build_proto_cmdclass(
3049
Returns:
3150
Options to pass to `setuptools.setup()` `cmdclass` argument to build
3251
protobuf files.
33-
34-
Examples:
35-
To use this you need to make sure you have these dependencies:
36-
37-
* `grpcio-tools >= 1.47.0, < 2`
38-
* `mypy-protobuf >= 3.0.0, < 4`
39-
40-
TODO: SUBMODULE
41-
42-
```py
43-
import setuptools
44-
45-
if __name__ == "__main__":
46-
setuptools.setup(cmdclass=build_proto_cmdclass())
47-
```
4852
"""
4953

5054
class CompileProto(setuptools.Command):
51-
"""Command class to build the Python protobuf files."""
55+
"""Build the Python protobuf files."""
5256

5357
description: str = f"compile protobuf files in {proto_path}/**/{proto_glob}/"
58+
"""Description of the command."""
59+
5460
user_options: list[str] = []
61+
"""Options of the command."""
5562

5663
def initialize_options(self) -> None:
5764
"""Initialize options."""
@@ -76,7 +83,7 @@ def run(self) -> None:
7683
subprocess.run(protoc_cmd, check=True)
7784

7885
class BuildPy(setuptools.command.build_py.build_py, CompileProto):
79-
"""Command class to build the Python protobuf files."""
86+
"""Build the Python protobuf files and run the regular `build_py` command."""
8087

8188
def run(self) -> None:
8289
"""Compile the Python protobuf files and run regular `build_py`."""

0 commit comments

Comments
 (0)