Skip to content

Commit 0ba142c

Browse files
committed
Replace darglint with pydoclint via flake8
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 (0.2s vs 20s for the SDK, 100x improvement). 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. 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. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 079333a commit 0ba142c

File tree

19 files changed

+181
-62
lines changed

19 files changed

+181
-62
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

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +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",
6669
"tomli == 2.0.1", # Needed by pydocstyle to read pyproject.toml
6770
]
6871
dev-formatting = ["black == 23.7.0", "isort == 5.12.0"]
@@ -99,7 +102,7 @@ dev-pytest = [
99102
{%- endif %}
100103
]
101104
dev = [
102-
"{{cookiecutter.pypi_package_name}}[dev-mkdocs,dev-docstrings,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
105+
"{{cookiecutter.pypi_package_name}}[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
103106
]
104107

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

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

pyproject.toml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +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",
6770
"tomli == 2.0.1", # Needed by pydocstyle to read pyproject.toml
6871
]
6972
dev-formatting = ["black == 23.7.0", "isort == 5.12.0"]
@@ -94,7 +97,7 @@ dev-pytest = [
9497
"sybil == 5.0.3", # Should be consistent with the extra-lint-examples dependency
9598
]
9699
dev = [
97-
"frequenz-repo-config[dev-mkdocs,dev-docstrings,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
100+
"frequenz-repo-config[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
98101
]
99102

100103
[project.urls]
@@ -113,6 +116,23 @@ profile = "black"
113116
line_length = 88
114117
src_paths = ["benchmarks", "examples", "src", "tests"]
115118

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

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
],

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def ci_checks_max(session: nox.Session) -> None:
2828
formatting(session, False)
2929
mypy(session, False)
3030
pylint(session, False)
31-
docstrings(session, False)
31+
flake8(session, False)
3232
pytest_max(session, False)
3333

3434

@@ -84,30 +84,18 @@ def pylint(session: nox.Session, install_deps: bool = True) -> None:
8484

8585

8686
@nox.session
87-
def docstrings(session: nox.Session, install_deps: bool = True) -> None:
88-
"""Check docstring tone with pydocstyle and param descriptions with darglint.
87+
def flake8(session: nox.Session, install_deps: bool = True) -> None:
88+
"""Check for common errors and in particular documentation format and style.
8989
9090
Args:
9191
session: the nox session.
9292
install_deps: True if dependencies should be installed.
9393
"""
9494
if install_deps:
95-
session.install("-e", ".[dev-docstrings]")
95+
session.install("-e", ".[dev-flake8]")
9696

9797
conf = _config.get()
98-
session.run("pydocstyle", *conf.opts.pydocstyle, *conf.path_args(session))
99-
100-
# Darglint checks that function argument and return values are documented.
101-
# This is needed only for the `src` dir, so we exclude the other top level
102-
# dirs that contain code, unless some paths were specified by argument, in
103-
# which case we use those untouched.
104-
darglint_paths = session.posargs or filter(
105-
# pylint: disable=fixme
106-
# TODO: Make these exclusions configurable
107-
lambda path: not (path.startswith("tests") or path.startswith("benchmarks")),
108-
conf.path_args(session),
109-
)
110-
session.run("darglint", *conf.opts.darglint, *darglint_paths)
98+
session.run("flake8", *conf.opts.flake8, *conf.path_args(session))
11199

112100

113101
@nox.session

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/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

0 commit comments

Comments
 (0)