Skip to content

Commit be370ff

Browse files
committed
Improve general module documentation
Split `nox` sections into a section for writing the `noxfile.py` and a section about configuring the `pyproject.toml` file. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent d4ec142 commit be370ff

File tree

1 file changed

+95
-21
lines changed

1 file changed

+95
-21
lines changed

src/frequenz/repo/config/__init__.py

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,11 @@
1414
1515
## `nox`
1616
17+
### Writing the `noxfile.py`
18+
1719
Projects wanting to use `nox` to run lint checkers and other utilities can use
1820
the [`frequenz.repo.config.nox`][] package.
1921
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-
3522
When writing the `noxfile.py` you should import the `nox` module from this
3623
package and use the [`frequenz.repo.config.nox.configure`][] function,
3724
which will configure all nox sessions.
@@ -40,9 +27,9 @@
4027
in the [`frequenz.repo.config.nox.default`][] module. For example:
4128
4229
```python
43-
from frequenz.repo import config
30+
from frequenz.repo.config import nox
4431
45-
config.nox.configure(config.nox.default.lib_config)
32+
nox.configure(nox.default.lib_config)
4633
```
4734
4835
Again, make sure to pick the correct default configuration based on the type of
@@ -53,11 +40,11 @@
5340
[`copy()`][frequenz.repo.config.nox.config.Config.copy] method:
5441
5542
```python
56-
from frequenz.repo import config
43+
from frequenz.repo.config import nox
5744
58-
conf = config.nox.default.lib_config.copy()
59-
conf.opts.black.append("--diff")
60-
config.nox.configure(conf)
45+
config = nox.default.lib_config.copy()
46+
config.opts.black.append("--diff")
47+
nox.configure(config)
6148
```
6249
6350
If you need further customization or to define new sessions, you can use the
@@ -73,6 +60,93 @@
7360
7461
- [`frequenz.repo.config.nox.util`][]: General purpose utility functions.
7562
63+
### `pyproject.toml` configuration
64+
65+
All sessions configured by this package expect the `pyproject.toml` file to
66+
define specific *dev* dependencies that will be used by the different `nox`
67+
sessions.
68+
69+
The following optional dependencies are used and must be defined:
70+
71+
- `dev-docstrings`: Dependencies to lint the documentation.
72+
73+
At least these packages should be included:
74+
75+
- `pydocstyle`: To check the docstrings' format.
76+
- `darglint`: To check the docstrings' content.
77+
78+
- `dev-formatting`: Dependencies to check the code's formatting.
79+
80+
At least these packages should be included:
81+
82+
- `black`: To check the code's formatting.
83+
- `isort`: To check the imports' formatting.
84+
85+
- `dev-mypy`: Dependencies to run `mypy` to check the code's type annotations.
86+
87+
At least these packages should be included:
88+
89+
- `mypy`: To check the code's type annotations.
90+
91+
- `dev-pylint`: Dependencies to run `pylint` to lint the code.
92+
93+
At least these packages should be included:
94+
95+
- `pylint`: To lint the code.
96+
97+
- `dev-pytest`: Dependencies to run the tests using `pytest`.
98+
99+
At least these packages should be included:
100+
101+
- `pytest`: To run the tests.
102+
103+
For some of these you should install too any other dependencies that are used
104+
by the project. For example, if the project uses `pytest-asyncio`, you should
105+
include it in the `dev-pytest` optional dependency.
106+
107+
It is also recommended, but not required, to provide a global `dev` optional
108+
dependency that includes all the other optional dependencies, so users can
109+
install all the dependencies needed while developing the project without having
110+
to run `nox`, which might be a bit slow if you want to do quick iterations.
111+
112+
```console
113+
$ pip install -e .[dev]
114+
...
115+
$ pytest
116+
...
117+
```
118+
119+
Here is a sample `pyproject.toml` file that defines all the optional
120+
dependencies:
121+
122+
```toml
123+
[project]
124+
name = "my-package"
125+
# ...
126+
127+
[project.optional-dependencies]
128+
dev-docstrings = ["pydocstyle == 6.3.0", "darglint == 1.8.1"]
129+
dev-formatting = ["black == 23.3.0", "isort == 5.12.0"]
130+
dev-mypy = [
131+
"mypy == 1.1.1",
132+
# For checking tests
133+
"my-package[dev-pytest]",
134+
]
135+
dev-pylint = [
136+
"pylint == 2.17.1",
137+
"pylint-google-style-guide-imports-enforcing == 1.3.0",
138+
# For checking tests
139+
"my-package[dev-pytest]",
140+
]
141+
dev-pytest = [
142+
"pytest == 7.2.2",
143+
"pytest-asyncio == 0.21.0",
144+
"pytest-mock == 3.10.0",
145+
]
146+
dev = [
147+
"my-package[dev-docstrings,dev-formatting,dev-mypy,dev-nox,dev-pylint,dev-pytest]",
148+
]
149+
```
76150
77151
# APIs
78152

0 commit comments

Comments
 (0)