Skip to content

Commit 7a6802f

Browse files
authored
Replace darglint with pydoclint (frequenz-floss#124)
The `darglint` project is not maintained anymore, and even when there is a fork that is trying to keep it alive, it is still extremely slow. The new project `pydoclint` was created recently but advancing rapidly, and already in better shape than `darglint` and way faster. To be able to add ignore comments in the code, `pydoclint` needs to be run via `flake8`. Because we need to run `flake8` already, and `pydocstyle` also can run via `flake8`, we are merging both in one `flake8` call, so we only need to read the files once. Performance running on the for the SDK `src` directory only: <table> <tr> <td>darling <td>20s (1x) <tr> <td>pydoclint <td>0.2s (100x) <tr> <td>flake8 (basic checks + pydocstyle + pydoclint) <td>0.6s (33x) </table> As a side effect, we are also enabling other base `flake8` checks. There is probably some overlap with `pylint`, but `flake8` is very fast anyway, so it shouldn't be noticed (for the SDK, `flake8` basic checks + `pydocstyle` + `pydoclint` runs in 0.6s and `pylint` alone runs in 15s). At some point we might want to disable the duplicated checks in `pylint` to see if it speeds up `pylint`. This commit also renames the `dev-docstrings` optional dependency to `dev-flake8` because now is not checking docstrings exclusively.
2 parents 079333a + 57630ac commit 7a6802f

File tree

23 files changed

+203
-79
lines changed

23 files changed

+203
-79
lines changed

.darglint

Lines changed: 0 additions & 2 deletions
This file was deleted.

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
exclude .cookiecutter-replay.json
2-
exclude .darglint
32
exclude .editorconfig
43
exclude .gitignore
54
exclude CODEOWNERS

RELEASE_NOTES.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,36 @@
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
- `flake8` basic checks are enabled now. Most are already covered by `pylint`, but there are a few differences, so you might need to fix your code if `flake8` find some issues.
10+
11+
- `darglint` was replaced by `pydoclint`, `pydoclint` can find a few more issues than `darglint`, so your code might need adjusting.
12+
13+
- `darglint` is not used anymore, but if it is installed, it will make `flake8` run extremely slowly anyways, so it is extremely recommended to uninstall it (`pip uninstall darglint`) and rebuild you `nox` *venvs* if you use `-R`.
14+
15+
- If you are upgrading without regenerating the cookiecutter templates, you'll need to adjust the dependencies accordingly.
1016

1117
### Cookiecutter template
1218

13-
<!-- Here upgrade steps for cookiecutter specifically -->
19+
- CI: The `nox` job now uses a matrix to run the different `nox` sessions in parallel. If you use branch projection with the `nox` job you need to update the rules to include each matrix job.
20+
21+
- See the general upgrading section.
1422

1523
## New Features
1624

17-
<!-- Here goes the main new features and examples or instructions on how to use them -->
25+
- `flake8` is now used to check the files.
1826

19-
### Cookiecutter template
27+
- `darlint` was replaced by `pydoclint`, which is way faster and detect more issues.
2028

29+
### Cookiecutter template
2130

2231
- Now dependabot updates will be done weekly and grouped by *required* and *optional* for minor and patch updates (major updates are still done individually for each dependency).
2332

2433
- ci: Add debug information when installing pip packages.
2534

2635
The output of `pip freeze` is printed to be able to more easily debug different behaviours between GitHub workflow runs and local runs.
2736

37+
- See the general new features section.
38+
2839
## Bug Fixes
2940

3041
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

cookiecutter/local_extensions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ def introduction(
230230
231231
Welcome to repo-config Cookiecutter template!
232232
233-
This template will help you to create a new repository for your project. You will be asked to provide some information about your project.
233+
This template will help you to create a new repository for your project. \
234+
You will be asked to provide some information about your project.
234235
235236
Here is an explanation of what each variable is for and will be used for:
236237

cookiecutter/{{cookiecutter.github_repo_name}}/MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
exclude .cookiecutter-replay.json
2-
exclude .darglint
32
exclude .editorconfig
43
exclude .gitignore
54
{%- if cookiecutter.type == "api" %}

cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ email = "{{cookiecutter.author_email}}"
6060

6161
# TODO(cookiecutter): Remove and add more optional dependencies if appropriate
6262
[project.optional-dependencies]
63-
dev-docstrings = [
63+
dev-flake8 = [
64+
"flake8 == 6.1.0",
65+
"flake8-docstrings == 1.7.0",
66+
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
67+
"pydoclint == 0.3.0",
6468
"pydocstyle == 6.3.0",
65-
"darglint == 1.8.1",
66-
"tomli == 2.0.1", # Needed by pydocstyle to read pyproject.toml
6769
]
6870
dev-formatting = ["black == 23.7.0", "isort == 5.12.0"]
6971
dev-mkdocs = [
@@ -99,7 +101,7 @@ dev-pytest = [
99101
{%- endif %}
100102
]
101103
dev = [
102-
"{{cookiecutter.pypi_package_name}}[dev-mkdocs,dev-docstrings,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
104+
"{{cookiecutter.pypi_package_name}}[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
103105
]
104106

105107
[project.urls]
@@ -121,6 +123,23 @@ line_length = 88
121123
{#- We don't include "py" here for API because we don't want to check generated files #}
122124
src_paths = ["benchmarks", "examples", "src", "tests"]
123125

126+
[tool.flake8]
127+
# We give some flexibility to go over 88, there are cases like long URLs or
128+
# code in documenation that have extra indentation. Black will still take care
129+
# of making everything that can be 88 wide, 88 wide.
130+
max-line-length = 100
131+
extend-ignore = [
132+
"E203", # Whitespace before ':' (conflicts with black)
133+
"W503", # Line break before binary operator (conflicts with black)
134+
]
135+
# pydoclint options
136+
style = "google"
137+
check-return-types = false
138+
check-yield-types = false
139+
arg-type-hints-in-docstring = false
140+
arg-type-hints-in-signature = true
141+
allow-init-docstring = true
142+
124143
[tool.pylint.similarities]
125144
ignore-comments = ['yes']
126145
ignore-docstrings = ['yes']

pyproject.toml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ extra-lint-examples = [
6161
"pytest >= 7.3.0, < 8",
6262
"sybil >= 5.0.3, < 6",
6363
]
64-
dev-docstrings = [
64+
dev-flake8 = [
65+
"flake8 == 6.1.0",
66+
"flake8-docstrings == 1.7.0",
67+
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
68+
"pydoclint == 0.3.0",
6569
"pydocstyle == 6.3.0",
66-
"darglint == 1.8.1",
67-
"tomli == 2.0.1", # Needed by pydocstyle to read pyproject.toml
6870
]
6971
dev-formatting = ["black == 23.7.0", "isort == 5.12.0"]
7072
dev-mkdocs = [
@@ -94,7 +96,7 @@ dev-pytest = [
9496
"sybil == 5.0.3", # Should be consistent with the extra-lint-examples dependency
9597
]
9698
dev = [
97-
"frequenz-repo-config[dev-mkdocs,dev-docstrings,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
99+
"frequenz-repo-config[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
98100
]
99101

100102
[project.urls]
@@ -113,6 +115,23 @@ profile = "black"
113115
line_length = 88
114116
src_paths = ["benchmarks", "examples", "src", "tests"]
115117

118+
[tool.flake8]
119+
# We give some flexibility to go over 88, there are cases like long URLs or
120+
# code in documenation that have extra indentation. Black will still take care
121+
# of making everything that can be 88 wide, 88 wide.
122+
max-line-length = 100
123+
extend-ignore = [
124+
"E203", # Whitespace before ':' (conflicts with black)
125+
"W503", # Line break before binary operator (conflicts with black)
126+
]
127+
# pydoclint options
128+
style = "google"
129+
check-return-types = false
130+
check-yield-types = false
131+
arg-type-hints-in-docstring = false
132+
arg-type-hints-in-signature = true
133+
allow-init-docstring = true
134+
116135
[tool.pylint.similarities]
117136
ignore-comments = ['yes']
118137
ignore-docstrings = ['yes']

src/frequenz/repo/config/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@
7373
7474
The following optional dependencies are used and must be defined:
7575
76-
- `dev-docstrings`: Dependencies to lint the documentation.
76+
- `dev-flake8`: Dependencies to do flake8 lint, including the documentation.
7777
7878
At least these packages should be included:
7979
8080
- `pydocstyle`: To check the docstrings' format.
81-
- `darglint`: To check the docstrings' content.
81+
- `pydoclint`: To check the docstrings' content.
8282
8383
- `dev-formatting`: Dependencies to check the code's formatting.
8484
@@ -130,7 +130,13 @@
130130
# ...
131131
132132
[project.optional-dependencies]
133-
dev-docstrings = ["pydocstyle == 6.3.0", "darglint == 1.8.1"]
133+
dev-flake8 = [
134+
"flake8 == 6.1.0",
135+
"flake8-docstrings == 1.7.0",
136+
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
137+
"pydoclint == 0.2.4",
138+
"pydocstyle == 6.3.0",
139+
]
134140
dev-formatting = ["black == 23.3.0", "isort == 5.12.0"]
135141
dev-mkdocs = [
136142
"mike == 1.1.2",
@@ -157,7 +163,7 @@
157163
"pytest-mock == 3.10.0",
158164
]
159165
dev = [
160-
"my-package[dev-mkdocs,dev-docstrings,dev-formatting,dev-mypy,dev-nox,dev-pylint,dev-pytest]",
166+
"my-package[dev-mkdocs,dev-flake8,dev-formatting,dev-mypy,dev-nox,dev-pylint,dev-pytest]",
161167
]
162168
```
163169

src/frequenz/repo/config/nox/config.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@ class CommandsOptions:
2929
black: list[str] = _dataclasses.field(default_factory=lambda: [])
3030
"""Command-line options for the `black` command."""
3131

32-
darglint: list[str] = _dataclasses.field(default_factory=lambda: [])
33-
"""Command-line options for the `darglint` command."""
32+
flake8: list[str] = _dataclasses.field(default_factory=lambda: [])
33+
"""Command-line options for the `flake8` command."""
3434

3535
isort: list[str] = _dataclasses.field(default_factory=lambda: [])
3636
"""Command-line options for the `isort` command."""
3737

3838
mypy: list[str] = _dataclasses.field(default_factory=lambda: [])
3939
"""Command-line options for the `mypy` command."""
4040

41-
pydocstyle: list[str] = _dataclasses.field(default_factory=lambda: [])
42-
"""Command-line options for the `pydocstyle` command."""
43-
4441
pylint: list[str] = _dataclasses.field(default_factory=lambda: [])
4542
"""Command-line options for the `pylint` command."""
4643

@@ -56,10 +53,9 @@ def copy(self) -> Self:
5653
return _dataclasses.replace(
5754
self,
5855
black=self.black.copy(),
59-
darglint=self.darglint.copy(),
56+
flake8=self.flake8.copy(),
6057
isort=self.isort.copy(),
6158
mypy=self.mypy.copy(),
62-
pydocstyle=self.pydocstyle.copy(),
6359
pylint=self.pylint.copy(),
6460
pytest=self.pytest.copy(),
6561
)
@@ -239,7 +235,7 @@ def configure(
239235
# We need to make sure sessions are imported, otherwise they won't be visible to nox.
240236
if import_default_sessions:
241237
# pylint: disable=import-outside-toplevel,cyclic-import
242-
from . import session as _
238+
from . import session as _ # noqa: F401
243239

244240
match conf:
245241
case Config():

src/frequenz/repo/config/nox/default.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
black=[
3131
"--check",
3232
],
33-
darglint=[
34-
"-v2", # for verbose error messages.
35-
],
33+
flake8=[],
3634
isort=[
3735
"--diff",
3836
"--check",
@@ -56,9 +54,9 @@
5654
opts=common_command_options.copy(),
5755
sessions=[
5856
"formatting",
57+
"flake8",
5958
"mypy",
6059
"pylint",
61-
"docstrings",
6260
"pytest_min",
6361
"pytest_max",
6462
],

0 commit comments

Comments
 (0)