Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ repos:
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-no-log-warn
- id: python-use-type-annotations
- id: text-unicode-replacement-char

- repo: https://github.com/asottile/pyupgrade
rev: v3.21.2
Expand All @@ -35,7 +38,7 @@ repos:
- "--py310-plus"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.15.9"
rev: "v0.15.11"
hooks:
- id: ruff-check
args:
Expand Down
5 changes: 3 additions & 2 deletions mkdocs_rss_plugin/git_manager/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# ##################################

# standard library
from os import environ, path
from os import environ
from pathlib import Path

# 3rd party
from git import Git
Expand Down Expand Up @@ -111,4 +112,4 @@ def is_shallow_clone(self) -> bool:
Returns:
bool: True if a repo is shallow clone
"""
return path.exists(".git/shallow")
return Path(".git/shallow").exists()
15 changes: 8 additions & 7 deletions mkdocs_rss_plugin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
from __future__ import annotations

# standard
from collections.abc import MutableMapping
from dataclasses import dataclass, field
from datetime import datetime
from pathlib import Path
from typing import Any

# 3rd party
from mkdocs.structure.pages import Page
from typing import TYPE_CHECKING, Any

# package modules
from mkdocs_rss_plugin.__about__ import __title__, __version__

if TYPE_CHECKING:
from collections.abc import MutableMapping
from datetime import datetime
from pathlib import Path

from mkdocs.structure.pages import Page

# ############################################################################
# ########## Classes ###############
# ##################################
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_rss_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class GitRssPlugin(BasePlugin[RssPluginConfig]):
# allow to set the plugin multiple times in the same mkdocs config
supports_multiple_instances = True

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
"""Instantiation."""
# pages storage
super().__init__(*args, **kwargs)
Expand Down
30 changes: 17 additions & 13 deletions mkdocs_rss_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# ##################################

# standard library
import logging
from collections.abc import Iterable
from datetime import date, datetime
from functools import lru_cache
Expand Down Expand Up @@ -76,16 +75,21 @@ def __init__(
mkdocs_command_is_on_serve: bool = False,
path: str = ".",
use_git: bool = True,
):
) -> None:
"""Class hosting the plugin logic.

Args:
path (str, optional): path to the git repository to use. Defaults to ".".
use_git (bool, optional): flag to use git under the hood or not. Defaults to True.
cache_dir: _description_. Defaults to DEFAULT_CACHE_FOLDER.
integration_material_blog (bool, optional): option to enable
integration with Blog plugin from Material theme. Defaults to True.
integration with Blog plugin from Material theme. \
Defaults to None.
integration_material_social_cards (bool, optional): option to enable
integration with Social Cards plugin from Material theme. Defaults to True.
integration with Social Cards plugin from Material theme. \
Defaults to None.
mkdocs_command_is_on_serve: _description_. Defaults to False.
path (str, optional): path to the git repository to use. Defaults to ".".
use_git (bool, optional): flag to use git under the hood or not. \
Defaults to True.
"""
self.mkdocs_command_is_on_serve = mkdocs_command_is_on_serve
if self.mkdocs_command_is_on_serve:
Expand Down Expand Up @@ -294,20 +298,20 @@ def get_file_dates(
format="%at",
)
except GitCommandError as err:
logging.warning(
logger.info(
f"Unable to read git logs of '{in_page.file.abs_src_path}'. "
"Is git log readable? Falling back to build date. "
"To disable this warning, set 'use_git: false' in plugin options. "
f"Trace: {err}"
)
except GitCommandNotFound as err:
logging.error(
logger.warning(
"Unable to perform command 'git log'. Is git installed? "
"Falling back to build date. "
"To disable this warning, set 'use_git: false' in plugin options. "
f"Trace: {err}"
)
self.git_is_valid = 0
self.git_is_valid = False
# convert timestamps into datetimes
if isinstance(dt_created, (str, float, int)) and dt_created:
dt_created = set_datetime_zoneinfo(
Expand Down Expand Up @@ -374,7 +378,7 @@ def get_authors_from_meta(self, in_page: Page) -> Optional[tuple[str]]:
elif isinstance(in_page.meta.get("author"), (list, tuple)):
return tuple(in_page.meta.get("author"))
else:
logging.warning(
logger.warning(
"Type of author value in page.meta "
f"({in_page.file.abs_src_path}) is not valid. "
"It should be str, list or tuple, "
Expand All @@ -396,7 +400,7 @@ def get_authors_from_meta(self, in_page: Page) -> Optional[tuple[str]]:
else:
return tuple(in_page.meta.get("authors"))
else:
logging.warning(
logger.warning(
"Type of authors value in page.meta (%s) is not valid. "
"It should be str, list or tuple, not: %s."
% in_page.file.abs_src_path,
Expand Down Expand Up @@ -754,8 +758,8 @@ def get_site_url(mkdocs_config: MkDocsConfig) -> Optional[str]:
Returns:
str | None: site url
"""
# this method exists because the following line returns an empty string instead of \
# None (because the key always exists)
# this method exists because the following line returns an empty string instead
# of None (because the key always exists)
defined_site_url = mkdocs_config.site_url

# cases
Expand Down
51 changes: 51 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,57 @@ line_length = 88
multi_line_output = 3
use_parentheses = true

[tool.ruff]
line-length = 88
target-version = "py310"
exclude = [".git", "__pycache__", "old", "build", "dist", "tests/dev", ".venv*"]

[tool.ruff.format]
docstring-code-format = true
docstring-code-line-length = "dynamic"
indent-style = "space"
line-ending = "auto"
quote-style = "double"
skip-magic-trailing-comma = false

[tool.ruff.lint]
select = [
"A", # flake8-builtins
"ANN", # flake8-annotations
"B", # flake8-bugbear
"C90", # mccabe complexity
"E", # pycodestyle errors
"ERA", # eradicate (commented code)
"F", # pyflakes
"I", # isort
"LOG", # flake8-logging
"N", # pep8-naming
"PTH", # flake8-pathlib
"S", # bandit security
"TC", # flake8-type-checking
"T20", # flake8-print
"W", # pycodestyle warnings
]

ignore = [
"ANN201", # Missing return type annotation for public function
"ANN204", # Missing return type annotation for special method `__init__`
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
"E501", # line too long (handled by black)
# "E203", # whitespace before ':'
# "E226", # missing whitespace around arithmetic operator
# "E24", # multiple spaces after ','
]

[tool.ruff.lint.per-file-ignores]
# Ignore `E402` (import violations) in all `__init__.py` files
"__init__.py" = ["E402"]
# Ignore rules in tests
"tests/test_*.py" = ["ANN001", "ANN2", "S101", "T20"]

[tool.ruff.lint.pydocstyle]
convention = "google"

# Pytest configuration
[tool.pytest.ini_options]
addopts = [
Expand Down
2 changes: 1 addition & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Base class for unit tests."""

Expand Down
2 changes: 1 addition & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Usage from the repo root folder:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_no_git.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Usage from the repo root folder:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Usage from the repo root folder:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_integrations_material.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Usage from the repo root folder:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_integrations_material_blog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Usage from the repo root folder:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_integrations_material_social_cards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Usage from the repo root folder:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_no_material.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Test build without Material theme installed.

Expand Down
2 changes: 1 addition & 1 deletion tests/test_rss_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Usage from the repo root folder:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_timezoner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! python3 # noqa E265
#! python3 # noqa: E265

"""Usage from the repo root folder:

Expand Down
Loading