diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 185e73e..babafdd 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 + git diff --color --exit-code - name: Check types + if: always() run: | hatch run types:check diff --git a/mkdocs_section_index/plugin.py b/mkdocs_section_index/plugin.py index ab43d23..2342f07 100644 --- a/mkdocs_section_index/plugin.py +++ b/mkdocs_section_index/plugin.py @@ -2,14 +2,17 @@ import collections import logging +from typing import TYPE_CHECKING -from jinja2 import Environment from mkdocs.plugins import BasePlugin from mkdocs.structure.nav import Navigation, Section from mkdocs.structure.pages import Page from . import SectionPage, rewrites +if TYPE_CHECKING: + from jinja2 import Environment + __all__ = ["SectionIndexPlugin"] log = logging.getLogger(f"mkdocs.plugins.{__name__}") diff --git a/pyproject.toml b/pyproject.toml index 24382e1..e4d6792 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ include = ["/mkdocs_section_index", "/tests"] [tool.hatch.envs.default.scripts] all = [ - "hatch run style:format", + "hatch run style:fix", "hatch run types:check", "hatch run test:test", ] @@ -85,15 +85,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_section_index tests", + "format", +] format = [ - "find mkdocs_section_index tests -name '*.py' | xargs pyupgrade --exit-zero-even-if-changed --py37-plus", - "autoflake -r mkdocs_section_index tests", "isort -q mkdocs_section_index tests", "black -q mkdocs_section_index 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 diff --git a/tests/conftest.py b/tests/conftest.py index 43458da..f958d83 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,6 @@ import functools import http.server import logging -import sys import threading import pytest @@ -20,8 +19,6 @@ def cap_log(): @pytest.fixture(scope="session") def http_server(tmp_path_factory): - if sys.version_info < (3, 7): - pytest.skip("limitation of http.server", allow_module_level=True) directory = tmp_path_factory.mktemp("http_server") httpd = http.server.HTTPServer( ("localhost", 0), diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 6d3284a..016fce4 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -80,7 +80,7 @@ def test_nav_repr(golden, tmpdir): @contextlib.contextmanager def template_test(directory): - config = dict() + config = {} files = FakeFiles(config) env = Environment(loader=FileSystemLoader(directory)) env.filters["url"] = lambda s: s