Skip to content

Commit f412510

Browse files
authored
Quality: customize ruff config, extend git hooks and apply changes (#438)
2 parents 6dc7f76 + 51baad7 commit f412510

16 files changed

Lines changed: 94 additions & 34 deletions

.pre-commit-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ repos:
2525
- repo: https://github.com/pre-commit/pygrep-hooks
2626
rev: v1.10.0
2727
hooks:
28+
- id: python-check-blanket-noqa
29+
- id: python-no-log-warn
2830
- id: python-use-type-annotations
31+
- id: text-unicode-replacement-char
2932

3033
- repo: https://github.com/asottile/pyupgrade
3134
rev: v3.21.2
@@ -35,7 +38,7 @@ repos:
3538
- "--py310-plus"
3639

3740
- repo: https://github.com/astral-sh/ruff-pre-commit
38-
rev: "v0.15.9"
41+
rev: "v0.15.11"
3942
hooks:
4043
- id: ruff-check
4144
args:

mkdocs_rss_plugin/git_manager/ci.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# ##################################
66

77
# standard library
8-
from os import environ, path
8+
from os import environ
9+
from pathlib import Path
910

1011
# 3rd party
1112
from git import Git
@@ -111,4 +112,4 @@ def is_shallow_clone(self) -> bool:
111112
Returns:
112113
bool: True if a repo is shallow clone
113114
"""
114-
return path.exists(".git/shallow")
115+
return Path(".git/shallow").exists()

mkdocs_rss_plugin/models.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
from __future__ import annotations
99

1010
# standard
11-
from collections.abc import MutableMapping
1211
from dataclasses import dataclass, field
13-
from datetime import datetime
14-
from pathlib import Path
15-
from typing import Any
16-
17-
# 3rd party
18-
from mkdocs.structure.pages import Page
12+
from typing import TYPE_CHECKING, Any
1913

2014
# package modules
2115
from mkdocs_rss_plugin.__about__ import __title__, __version__
2216

17+
if TYPE_CHECKING:
18+
from collections.abc import MutableMapping
19+
from datetime import datetime
20+
from pathlib import Path
21+
22+
from mkdocs.structure.pages import Page
23+
2324
# ############################################################################
2425
# ########## Classes ###############
2526
# ##################################

mkdocs_rss_plugin/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class GitRssPlugin(BasePlugin[RssPluginConfig]):
6060
# allow to set the plugin multiple times in the same mkdocs config
6161
supports_multiple_instances = True
6262

63-
def __init__(self, *args, **kwargs):
63+
def __init__(self, *args, **kwargs) -> None:
6464
"""Instantiation."""
6565
# pages storage
6666
super().__init__(*args, **kwargs)

mkdocs_rss_plugin/util.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# ##################################
66

77
# standard library
8-
import logging
98
from collections.abc import Iterable
109
from datetime import date, datetime
1110
from functools import lru_cache
@@ -76,16 +75,21 @@ def __init__(
7675
mkdocs_command_is_on_serve: bool = False,
7776
path: str = ".",
7877
use_git: bool = True,
79-
):
78+
) -> None:
8079
"""Class hosting the plugin logic.
8180
8281
Args:
83-
path (str, optional): path to the git repository to use. Defaults to ".".
84-
use_git (bool, optional): flag to use git under the hood or not. Defaults to True.
82+
cache_dir: _description_. Defaults to DEFAULT_CACHE_FOLDER.
8583
integration_material_blog (bool, optional): option to enable
86-
integration with Blog plugin from Material theme. Defaults to True.
84+
integration with Blog plugin from Material theme. \
85+
Defaults to None.
8786
integration_material_social_cards (bool, optional): option to enable
88-
integration with Social Cards plugin from Material theme. Defaults to True.
87+
integration with Social Cards plugin from Material theme. \
88+
Defaults to None.
89+
mkdocs_command_is_on_serve: _description_. Defaults to False.
90+
path (str, optional): path to the git repository to use. Defaults to ".".
91+
use_git (bool, optional): flag to use git under the hood or not. \
92+
Defaults to True.
8993
"""
9094
self.mkdocs_command_is_on_serve = mkdocs_command_is_on_serve
9195
if self.mkdocs_command_is_on_serve:
@@ -294,20 +298,20 @@ def get_file_dates(
294298
format="%at",
295299
)
296300
except GitCommandError as err:
297-
logging.warning(
301+
logger.info(
298302
f"Unable to read git logs of '{in_page.file.abs_src_path}'. "
299303
"Is git log readable? Falling back to build date. "
300304
"To disable this warning, set 'use_git: false' in plugin options. "
301305
f"Trace: {err}"
302306
)
303307
except GitCommandNotFound as err:
304-
logging.error(
308+
logger.warning(
305309
"Unable to perform command 'git log'. Is git installed? "
306310
"Falling back to build date. "
307311
"To disable this warning, set 'use_git: false' in plugin options. "
308312
f"Trace: {err}"
309313
)
310-
self.git_is_valid = 0
314+
self.git_is_valid = False
311315
# convert timestamps into datetimes
312316
if isinstance(dt_created, (str, float, int)) and dt_created:
313317
dt_created = set_datetime_zoneinfo(
@@ -374,7 +378,7 @@ def get_authors_from_meta(self, in_page: Page) -> Optional[tuple[str]]:
374378
elif isinstance(in_page.meta.get("author"), (list, tuple)):
375379
return tuple(in_page.meta.get("author"))
376380
else:
377-
logging.warning(
381+
logger.warning(
378382
"Type of author value in page.meta "
379383
f"({in_page.file.abs_src_path}) is not valid. "
380384
"It should be str, list or tuple, "
@@ -396,7 +400,7 @@ def get_authors_from_meta(self, in_page: Page) -> Optional[tuple[str]]:
396400
else:
397401
return tuple(in_page.meta.get("authors"))
398402
else:
399-
logging.warning(
403+
logger.warning(
400404
"Type of authors value in page.meta (%s) is not valid. "
401405
"It should be str, list or tuple, not: %s."
402406
% in_page.file.abs_src_path,
@@ -754,8 +758,8 @@ def get_site_url(mkdocs_config: MkDocsConfig) -> Optional[str]:
754758
Returns:
755759
str | None: site url
756760
"""
757-
# this method exists because the following line returns an empty string instead of \
758-
# None (because the key always exists)
761+
# this method exists because the following line returns an empty string instead
762+
# of None (because the key always exists)
759763
defined_site_url = mkdocs_config.site_url
760764

761765
# cases

pyproject.toml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,57 @@ line_length = 88
148148
multi_line_output = 3
149149
use_parentheses = true
150150

151+
[tool.ruff]
152+
line-length = 88
153+
target-version = "py310"
154+
exclude = [".git", "__pycache__", "old", "build", "dist", "tests/dev", ".venv*"]
155+
156+
[tool.ruff.format]
157+
docstring-code-format = true
158+
docstring-code-line-length = "dynamic"
159+
indent-style = "space"
160+
line-ending = "auto"
161+
quote-style = "double"
162+
skip-magic-trailing-comma = false
163+
164+
[tool.ruff.lint]
165+
select = [
166+
"A", # flake8-builtins
167+
"ANN", # flake8-annotations
168+
"B", # flake8-bugbear
169+
"C90", # mccabe complexity
170+
"E", # pycodestyle errors
171+
"ERA", # eradicate (commented code)
172+
"F", # pyflakes
173+
"I", # isort
174+
"LOG", # flake8-logging
175+
"N", # pep8-naming
176+
"PTH", # flake8-pathlib
177+
"S", # bandit security
178+
"TC", # flake8-type-checking
179+
"T20", # flake8-print
180+
"W", # pycodestyle warnings
181+
]
182+
183+
ignore = [
184+
"ANN201", # Missing return type annotation for public function
185+
"ANN204", # Missing return type annotation for special method `__init__`
186+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
187+
"E501", # line too long (handled by black)
188+
# "E203", # whitespace before ':'
189+
# "E226", # missing whitespace around arithmetic operator
190+
# "E24", # multiple spaces after ','
191+
]
192+
193+
[tool.ruff.lint.per-file-ignores]
194+
# Ignore `E402` (import violations) in all `__init__.py` files
195+
"__init__.py" = ["E402"]
196+
# Ignore rules in tests
197+
"tests/test_*.py" = ["ANN001", "ANN2", "S101", "T20"]
198+
199+
[tool.ruff.lint.pydocstyle]
200+
convention = "google"
201+
151202
# Pytest configuration
152203
[tool.pytest.ini_options]
153204
addopts = [

tests/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! python3 # noqa E265
1+
#! python3 # noqa: E265
22

33
"""Base class for unit tests."""
44

tests/test_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! python3 # noqa E265
1+
#! python3 # noqa: E265
22

33
"""Usage from the repo root folder:
44

tests/test_build_no_git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! python3 # noqa E265
1+
#! python3 # noqa: E265
22

33
"""Usage from the repo root folder:
44

tests/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! python3 # noqa E265
1+
#! python3 # noqa: E265
22

33
"""Usage from the repo root folder:
44

0 commit comments

Comments
 (0)