Skip to content

Commit 81decb7

Browse files
committed
Add high-level documentation to the top-level package
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent d2eea99 commit 81decb7

File tree

1 file changed

+140
-1
lines changed

1 file changed

+140
-1
lines changed

src/frequenz/repo/config/__init__.py

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,146 @@
11
# License: MIT
22
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
33

4-
"""Frequenz project setup tools and common configuration."""
4+
"""Frequenz project setup tools and common configuration.
5+
6+
The tools are provided to configure 4 main types of repositories:
7+
8+
- APIs (api)
9+
- Actors (actor)
10+
- Applications (app)
11+
- Libraries (lib)
12+
13+
# Common
14+
15+
## `nox`
16+
17+
Projects wanting to use `nox` to run lint checkers and other utilities can use
18+
the [`frequenz.repo.config.nox`][] package.
19+
20+
Make sure to add this package as `dev` dependency to your project's
21+
`pyproject.tom` file, for example:
22+
23+
```toml
24+
[project.optional-dependencies]
25+
nox = [
26+
"nox == 2022.11.21",
27+
"frequenz-repo-config[lib] == 0.1.0",
28+
]
29+
```
30+
31+
Please note the `lib` optional dependency. Make sure you specify the correct
32+
one based on the type of your project (`api`, `actor`, `app`, `lib`). Also make
33+
sure to adjust the versions.
34+
35+
When writing the `noxfile.py` you should import the `nox` module from this
36+
package and use the [`frequenz.repo.config.nox.configure`][] function,
37+
which will configure all nox sessions.
38+
39+
You should call `configure()` using one of the default configurations provided
40+
in the [`frequenz.repo.config.nox.default`][] module. For example:
41+
42+
```python
43+
from frequenz.repo import config
44+
45+
config.nox.configure(config.nox.default.lib_config)
46+
```
47+
48+
Again, make sure to pick the correct default configuration based on the type of
49+
your project (`api_config`, `actor_config`, `app_config`, `lib_config`).
50+
51+
If you need to modify the configuration, you can copy one of the default
52+
configurations by using the
53+
[`copy()`][frequenz.repo.config.nox.config.Config.copy] method:
54+
55+
```python
56+
from frequenz.repo import config
57+
58+
conf = config.nox.default.lib_config.copy()
59+
conf.opts.black.append("--diff")
60+
config.nox.configure(conf)
61+
```
62+
63+
If you need further customization or to define new sessions, you can use the
64+
following modules:
65+
66+
- [`frequenz.repo.config.nox.config`][]: Low-level utilities to configure nox
67+
sessions. It defines the `Config` and CommandsOptions` classes and the actual
68+
implementation of the `configure()` function. It also defines the `get()`
69+
function, which can be used to get the currently used configuration object.
70+
71+
- [`frequenz.repo.config.nox.session`][]: Predefined nox sessions. These are
72+
the sessions that are used by default.
73+
74+
- [`frequenz.repo.config.nox.util`][]: General purpose utility functions.
75+
76+
77+
# APIs
78+
79+
## `setuptools` gRPC support
80+
81+
When configuring APIs it is assumed that they have a gRPC interface.
82+
83+
Normally Frequenz APIs use basic types from
84+
[`google/api-common-protos`](https://github.com/googleapis/api-common-protos),
85+
so you need to make sure the proper submodule is added to your project:
86+
87+
```sh
88+
mkdir submodules
89+
git submodule add https://github.com:googleapis/api-common-protos.git submodules/api-common-protos
90+
git commit -m "Add Google api-common-protos submodule" submodules/api-common-protos
91+
```
92+
93+
Then you need to create a `setup.py` file with the following content:
94+
95+
```py
96+
import setuptools
97+
98+
from frequenz.repo.config.setuptools import grpc_tools
99+
100+
if __name__ == "__main__":
101+
setuptools.setup(cmdclass=grpc_tools.build_proto_cmdclass())
102+
```
103+
104+
Then you need to add this package as a build dependency and a few extra
105+
dependencies to your project, for example:
106+
107+
```toml
108+
requires = [
109+
"setuptools >= 67.3.2, < 68",
110+
"setuptools_scm[toml] >= 7.1.0, < 8",
111+
"frequenz-repo-config[api] >= 0.1.0, < 0.2.0",
112+
]
113+
build-backend = "setuptools.build_meta"
114+
115+
[project]
116+
dependencies = [
117+
"googleapis-common-protos == 1.56.2",
118+
"grpcio == 1.51.0",
119+
]
120+
```
121+
122+
Note the `api` extra in `frequenz-repo-config[api]`, this will ensure all
123+
dependencies to build the protocol files will be installed when building the
124+
package. Of course you need to replace the version numbers with the correct
125+
ones too.
126+
127+
Finally you need to make sure to include the generated `*.pyi` files in the
128+
source distribution, as well as the Google api-common-protos files, as it
129+
is not handled automatically yet
130+
([#13](https://github.com/frequenz-floss/frequenz-repo-config-python/issues/13)):
131+
132+
```
133+
recursive-include py *.pyi
134+
recursive-include submodules/api-common-protos/google *.proto
135+
```
136+
137+
If you need to customize how the protobuf files are compiled, you can pass
138+
a path to look for the protobuf files, a glob pattern to find the protobuf
139+
files, and a list of paths to include when compiling the protobuf files. By
140+
default `submodules/api-common-protos` is used as an include path, so if
141+
yout configured the submodules in a different path, you need to pass the
142+
correct path to the `include_paths` argument.
143+
"""
5144

6145
from . import nox, setuptools
7146

0 commit comments

Comments
 (0)