diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 837896e..5e27342 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,13 +62,17 @@ jobs: - name: Install dependencies run: | hatch run style:pip freeze + hatch run types:pip freeze + - name: Check style + if: always() + run: | + hatch run style:fix - name: Check formatting + if: always() run: | hatch run style:format git diff --exit-code - - name: Install dependencies - run: | - hatch run types:pip freeze - name: Check types + if: always() run: | hatch run types:check diff --git a/mkdocs_gen_files/__init__.py b/mkdocs_gen_files/__init__.py index c088acb..c0cea4e 100644 --- a/mkdocs_gen_files/__init__.py +++ b/mkdocs_gen_files/__init__.py @@ -9,7 +9,7 @@ import logging from .editor import FilesEditor -from .nav import Nav # noqa +from .nav import Nav # noqa: F401 - re-export __version__ = "0.5.0" diff --git a/mkdocs_gen_files/config_items.py b/mkdocs_gen_files/config_items.py index 1340514..bf0d31e 100644 --- a/mkdocs_gen_files/config_items.py +++ b/mkdocs_gen_files/config_items.py @@ -18,11 +18,11 @@ def run_validation(self, value): raise ValidationError(f"Expected a list of items, but a {type(value)} was given.") result = [] - for item in value: + for _ in value: self.option_type.pre_validation(self._config, self._key_name) for item in value: result.append(self.option_type.validate(item)) - for item in value: + for _ in value: self.option_type.post_validation(self._config, self._key_name) return result diff --git a/mkdocs_gen_files/plugin.py b/mkdocs_gen_files/plugin.py index 2c9d140..5623112 100644 --- a/mkdocs_gen_files/plugin.py +++ b/mkdocs_gen_files/plugin.py @@ -5,24 +5,34 @@ import runpy import tempfile import urllib.parse +from typing import Callable -from mkdocs.config import Config from mkdocs.plugins import BasePlugin -from mkdocs.structure.files import Files -from mkdocs.structure.pages import Page try: from mkdocs.exceptions import PluginError except ImportError: PluginError = SystemExit # type: ignore +from typing import TYPE_CHECKING, TypeVar + from .config_items import ListOfFiles from .editor import FilesEditor +if TYPE_CHECKING: + from mkdocs.config import Config + from mkdocs.structure.files import Files + from mkdocs.structure.pages import Page + + T = TypeVar("T") + try: from mkdocs.plugins import event_priority except ImportError: - event_priority = lambda priority: lambda f: f # No-op fallback + + def event_priority(priority: float) -> Callable[[T], T]: + return lambda f: f # No-op fallback + log = logging.getLogger(f"mkdocs.plugins.{__name__}") diff --git a/pyproject.toml b/pyproject.toml index 3d6263e..c7c58ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,7 @@ include = ["/mkdocs_gen_files", "/tests"] [tool.hatch.envs.default.scripts] all = [ - "hatch run style:format", + "hatch run style:fix", "hatch run types:check", "hatch run test:test", ] @@ -81,15 +81,16 @@ check = [ [tool.hatch.envs.style] skip-install = true dependencies = [ - "pyupgrade", - "autoflake", + "ruff", "isort", "black", ] [tool.hatch.envs.style.scripts] +fix = [ + "ruff check --fix mkdocs_gen_files tests", + "format", +] format = [ - "find mkdocs_gen_files tests -name '*.py' | xargs pyupgrade --exit-zero-even-if-changed --py37-plus", - "autoflake -r mkdocs_gen_files tests", "isort -q mkdocs_gen_files tests", "black -q mkdocs_gen_files tests", ] @@ -112,11 +113,20 @@ line-length = 100 profile = "black" line_length = 100 -[tool.autoflake] -in-place = true -remove-all-unused-imports = true -remove-unused-variables = true -expand-star-imports = true +[tool.ruff] +select = [ + "F", "W", "E", "UP", "YTT", "C4", "FA", "PIE", "T20", "RSE", "TCH", "DTZ", + "B002", "B003", "B005", "B007", "B009", "B012", "B013", "B014", "B015", "B018", "B020", "B021", "B023", "B026", "B033", "B034", "B905", + "COM818", + "PERF101", + "PGH002", "PGH004", "PGH005", + "PLE", "PLW0120", "PLW0127", + "RUF001", "RUF007", "RUF010", "RUF100", "RUF200", + "SIM101", "SIM107", "SIM201", "SIM202", "SIM208", "SIM210", "SIM211", "SIM300", "SIM401", "SIM910", +] +ignore = ["E501", "E731"] +[tool.ruff.flake8-comprehensions] +allow-dict-calls-with-keyword-arguments = true [tool.mypy] ignore_missing_imports = true