Skip to content

Commit deca0ec

Browse files
authored
chore: Migrate to flake8, normalize docstrings (#3)
1 parent 71b30f3 commit deca0ec

6 files changed

Lines changed: 88 additions & 117 deletions

File tree

config/flake8.ini

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[flake8]
2+
exclude = fixtures,docs,site
3+
max-line-length = 132
4+
strictness = long
5+
docstring-convention = google
6+
ban-relative-imports = true
7+
ignore =
8+
# redundant with W0622 (builtin override), which is more precise about line number
9+
A001
10+
# missing docstring in magic method
11+
D105
12+
# whitespace before ':' (incompatible with Black)
13+
E203
14+
# redundant with E0602 (undefined variable)
15+
F821
16+
# black already deals with quoting
17+
Q000
18+
# use of assert
19+
S101
20+
# we are not parsing XML
21+
S405
22+
# line break before binary operator (incompatible with Black)
23+
W503
24+
# two-lowercase-letters variable DO conform to snake_case naming style
25+
C0103
26+
# redunant with D102 (missing docstring)
27+
C0116
28+
# line too long
29+
C0301
30+
# too many instance attributes
31+
R0902
32+
# too few public methods
33+
R0903
34+
# too many public methods
35+
R0904
36+
# too many branches
37+
R0912
38+
# too many methods
39+
R0913
40+
# too many local variables
41+
R0914
42+
# too many statements
43+
R0915
44+
# redundant with F401 (unused import)
45+
W0611
46+
# lazy formatting for logging calls
47+
W1203
48+
# short name
49+
VNE001

duties.py

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121

2222
def latest(lines: List[str], regex: Pattern) -> Optional[str]:
23-
"""
24-
Return the last released version.
23+
"""Return the last released version.
2524
2625
Arguments:
2726
lines: Lines of the changelog file.
@@ -38,8 +37,7 @@ def latest(lines: List[str], regex: Pattern) -> Optional[str]:
3837

3938

4039
def unreleased(versions: List[Version], last_release: str) -> List[Version]:
41-
"""
42-
Return the most recent versions down to latest release.
40+
"""Return the most recent versions down to latest release.
4341
4442
Arguments:
4543
versions: All the versions (released and unreleased).
@@ -55,8 +53,7 @@ def unreleased(versions: List[Version], last_release: str) -> List[Version]:
5553

5654

5755
def read_changelog(filepath: str) -> List[str]:
58-
"""
59-
Read the changelog file.
56+
"""Read the changelog file.
6057
6158
Arguments:
6259
filepath: The path to the changelog file.
@@ -69,8 +66,7 @@ def read_changelog(filepath: str) -> List[str]:
6966

7067

7168
def write_changelog(filepath: str, lines: List[str]) -> None:
72-
"""
73-
Write the changelog file.
69+
"""Write the changelog file.
7470
7571
Arguments:
7672
filepath: The path to the changelog file.
@@ -87,8 +83,7 @@ def update_changelog(
8783
template_url: str,
8884
commit_style: str,
8985
) -> None:
90-
"""
91-
Update the given changelog file in place.
86+
"""Update the given changelog file in place.
9287
9388
Arguments:
9489
inplace_file: The file to update in-place.
@@ -120,8 +115,7 @@ def update_changelog(
120115

121116
@duty
122117
def changelog(ctx):
123-
"""
124-
Update the changelog in-place with latest commits.
118+
"""Update the changelog in-place with latest commits.
125119
126120
Arguments:
127121
ctx: The context instance (passed automatically).
@@ -142,8 +136,7 @@ def changelog(ctx):
142136

143137
@duty(pre=["check_code_quality", "check_types", "check_docs", "check_dependencies"])
144138
def check(ctx): # noqa: W0613 (no use for the context argument)
145-
"""
146-
Check it all!
139+
"""Check it all!
147140
148141
Arguments:
149142
ctx: The context instance (passed automatically).
@@ -152,20 +145,18 @@ def check(ctx): # noqa: W0613 (no use for the context argument)
152145

153146
@duty
154147
def check_code_quality(ctx, files=PY_SRC):
155-
"""
156-
Check the code quality.
148+
"""Check the code quality.
157149
158150
Arguments:
159151
ctx: The context instance (passed automatically).
160152
files: The files to check.
161153
"""
162-
ctx.run(f"flakehell lint {files}", title="Checking code quality", pty=PTY)
154+
ctx.run(f"flake8 --config=config/flake8.ini {files}", title="Checking code quality", pty=PTY)
163155

164156

165157
@duty
166158
def check_dependencies(ctx):
167-
"""
168-
Check for vulnerabilities in dependencies.
159+
"""Check for vulnerabilities in dependencies.
169160
170161
Arguments:
171162
ctx: The context instance (passed automatically).
@@ -195,8 +186,7 @@ def check_dependencies(ctx):
195186

196187
@duty
197188
def check_docs(ctx):
198-
"""
199-
Check if the documentation builds correctly.
189+
"""Check if the documentation builds correctly.
200190
201191
Arguments:
202192
ctx: The context instance (passed automatically).
@@ -208,8 +198,7 @@ def check_docs(ctx):
208198

209199
@duty
210200
def check_types(ctx):
211-
"""
212-
Check that the code is correctly typed.
201+
"""Check that the code is correctly typed.
213202
214203
Arguments:
215204
ctx: The context instance (passed automatically).
@@ -219,8 +208,7 @@ def check_types(ctx):
219208

220209
@duty(silent=True)
221210
def clean(ctx):
222-
"""
223-
Delete temporary files.
211+
"""Delete temporary files.
224212
225213
Arguments:
226214
ctx: The context instance (passed automatically).
@@ -238,8 +226,7 @@ def clean(ctx):
238226

239227
@duty
240228
def docs(ctx):
241-
"""
242-
Build the documentation locally.
229+
"""Build the documentation locally.
243230
244231
Arguments:
245232
ctx: The context instance (passed automatically).
@@ -249,8 +236,7 @@ def docs(ctx):
249236

250237
@duty
251238
def docs_serve(ctx, host="127.0.0.1", port=8000):
252-
"""
253-
Serve the documentation (localhost:8000).
239+
"""Serve the documentation (localhost:8000).
254240
255241
Arguments:
256242
ctx: The context instance (passed automatically).
@@ -262,8 +248,7 @@ def docs_serve(ctx, host="127.0.0.1", port=8000):
262248

263249
@duty
264250
def docs_deploy(ctx):
265-
"""
266-
Deploy the documentation on GitHub pages.
251+
"""Deploy the documentation on GitHub pages.
267252
268253
Arguments:
269254
ctx: The context instance (passed automatically).
@@ -273,8 +258,7 @@ def docs_deploy(ctx):
273258

274259
@duty
275260
def format(ctx): # noqa: W0622 (we don't mind shadowing the format builtin)
276-
"""
277-
Run formatting tools on the code.
261+
"""Run formatting tools on the code.
278262
279263
Arguments:
280264
ctx: The context instance (passed automatically).
@@ -290,8 +274,7 @@ def format(ctx): # noqa: W0622 (we don't mind shadowing the format builtin)
290274

291275
@duty
292276
def release(ctx, version):
293-
"""
294-
Release a new Python package.
277+
"""Release a new Python package.
295278
296279
Arguments:
297280
ctx: The context instance (passed automatically).
@@ -311,8 +294,7 @@ def release(ctx, version):
311294

312295
@duty(silent=True)
313296
def coverage(ctx):
314-
"""
315-
Report coverage as text and HTML.
297+
"""Report coverage as text and HTML.
316298
317299
Arguments:
318300
ctx: The context instance (passed automatically).
@@ -323,8 +305,7 @@ def coverage(ctx):
323305

324306
@duty
325307
def test(ctx, cleancov: bool = True, match: str = ""):
326-
"""
327-
Run the test suite.
308+
"""Run the test suite.
328309
329310
Arguments:
330311
ctx: The context instance (passed automatically).

pyproject.toml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,37 +71,3 @@ balanced_wrapping = true
7171
default_section = "THIRDPARTY"
7272
known_first_party = "mkdocs_autorefs"
7373
include_trailing_comma = true
74-
75-
[tool.flakehell]
76-
format = "colored"
77-
max_line_length = 132
78-
show_source = false
79-
exclude = ["tests/fixtures"]
80-
81-
[tool.flakehell.plugins]
82-
"*" = [
83-
"+*",
84-
"-RST*", # we write docstrings in markdown, not rst
85-
"-A001", # redundant with W0622 (builtin override), which is more precise about line number
86-
"-D105", # missing docstring in magic method
87-
"-D212", # multi-line docstring summary should start at the first line
88-
"-E203", # whitespace before ‘:’ (incompatible with Black)
89-
"-F821", # redundant with E0602 (undefined variable)
90-
"-Q000", # black already deals with quoting
91-
"-S101", # use of assert
92-
"-S405", # we are not parsing XML
93-
"-W503", # line break before binary operator (incompatible with Black)
94-
"-C0103", # two-lowercase-letters variable DO conform to snake_case naming style
95-
"-C0116", # redunant with D102 (missing docstring)
96-
"-C0301", # line too long
97-
"-R0902", # too many instance attributes
98-
"-R0903", # too few public methods
99-
"-R0904", # too many public methods
100-
"-R0912", # too many branches
101-
"-R0913", # too many methods
102-
"-R0914", # too many local variables
103-
"-R0915", # too many statements
104-
"-W0611", # redundant with F401 (unused import)
105-
"-W1203", # lazy formatting for logging calls
106-
"-VNE001", # short name
107-
]

src/mkdocs_autorefs/plugin.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
This module contains the "mkdocs-autorefs" plugin.
1+
"""This module contains the "mkdocs-autorefs" plugin.
32
43
After each page is processed by the Markdown converter, this plugin stores absolute URLs of every HTML anchors
54
it finds to later be able to fix unresolved references.
@@ -27,8 +26,7 @@
2726

2827

2928
class AutorefsPlugin(BasePlugin):
30-
"""
31-
An `mkdocs` plugin.
29+
"""An `mkdocs` plugin.
3230
3331
This plugin defines the following event hooks:
3432
@@ -50,8 +48,7 @@ def __init__(self) -> None:
5048
self.get_fallback_anchor: Callable[[str], Optional[str]] = lambda identifier: None
5149

5250
def register_anchor(self, page: str, anchor: str):
53-
"""
54-
Register that an anchor corresponding to an identifier was encountered when rendering the page.
51+
"""Register that an anchor corresponding to an identifier was encountered when rendering the page.
5552
5653
Arguments:
5754
page: The relative URL of the current page. Examples: `'foo/bar/'`, `'foo/index.html'`
@@ -60,8 +57,7 @@ def register_anchor(self, page: str, anchor: str):
6057
self._url_map[anchor] = f"{page}#{anchor}"
6158

6259
def get_item_url(self, anchor: str) -> str:
63-
"""
64-
Return a site-relative URL with anchor to the identifier, if it's present anywhere.
60+
"""Return a site-relative URL with anchor to the identifier, if it's present anywhere.
6561
6662
Arguments:
6763
anchor: The anchor (without '#').
@@ -81,8 +77,7 @@ def get_item_url(self, anchor: str) -> str:
8177
raise
8278

8379
def on_config(self, config: Config, **kwargs) -> Config: # noqa: W0613,R0201 (unused arguments, cannot be static)
84-
"""
85-
Instantiate our Markdown extension.
80+
"""Instantiate our Markdown extension.
8681
8782
Hook for the [`on_config` event](https://www.mkdocs.org/user-guide/plugins/#on_config).
8883
In this hook, we instantiate our [`AutorefsExtension`][mkdocs_autorefs.references.AutorefsExtension]
@@ -100,8 +95,7 @@ def on_config(self, config: Config, **kwargs) -> Config: # noqa: W0613,R0201 (u
10095
return config
10196

10297
def on_page_markdown(self, markdown: str, page: Page, **kwargs) -> str: # noqa: W0613 (unused arguments)
103-
"""
104-
Remember which page is the current one.
98+
"""Remember which page is the current one.
10599
106100
Arguments:
107101
markdown: Input Markdown.
@@ -115,8 +109,7 @@ def on_page_markdown(self, markdown: str, page: Page, **kwargs) -> str: # noqa:
115109
return markdown
116110

117111
def on_page_content(self, html: str, page: Page, **kwargs) -> str: # noqa: W0613 (unused arguments)
118-
"""
119-
Map anchors to URLs.
112+
"""Map anchors to URLs.
120113
121114
Hook for the [`on_page_content` event](https://www.mkdocs.org/user-guide/plugins/#on_page_content).
122115
In this hook, we map the IDs of every anchor found in the table of contents to the anchors absolute URLs.
@@ -138,8 +131,7 @@ def on_page_content(self, html: str, page: Page, **kwargs) -> str: # noqa: W061
138131
return html
139132

140133
def map_urls(self, base_url: str, anchor: AnchorLink) -> None:
141-
"""
142-
Recurse on every anchor to map its ID to its absolute URL.
134+
"""Recurse on every anchor to map its ID to its absolute URL.
143135
144136
This method populates `self.url_map` by side-effect.
145137
@@ -152,8 +144,7 @@ def map_urls(self, base_url: str, anchor: AnchorLink) -> None:
152144
self.map_urls(base_url, child)
153145

154146
def on_post_page(self, output: str, page: Page, **kwargs) -> str: # noqa: W0613 (unused arguments)
155-
"""
156-
Fix cross-references.
147+
"""Fix cross-references.
157148
158149
Hook for the [`on_post_page` event](https://www.mkdocs.org/user-guide/plugins/#on_post_page).
159150
In this hook, we try to fix unresolved references of the form `[title][identifier]` or `[identifier][]`.

0 commit comments

Comments
 (0)