Skip to content

Commit 1f55a88

Browse files
authored
🔧 Update pre-commit (#62)
1 parent 19587f0 commit 1f55a88

22 files changed

+74
-38
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v4
18-
- name: Set up Python 3.8
18+
- name: Set up Python 3.9
1919
uses: actions/setup-python@v5
2020
with:
21-
python-version: "3.8"
22-
- uses: pre-commit/[email protected].0
21+
python-version: "3.9"
22+
- uses: pre-commit/[email protected].1
2323

2424
tests:
2525

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ exclude: ^tests/.*\.md|tests/.*\.rst|tests/.*\.xml|docs/apidocs/.*
55

66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v4.5.0
8+
rev: v4.6.0
99
hooks:
1010
- id: trailing-whitespace
1111
- id: end-of-file-fixer
1212
- id: check-yaml
1313

1414
- repo: https://github.com/astral-sh/ruff-pre-commit
15-
rev: v0.1.11
15+
rev: v0.4.4
1616
hooks:
1717
- id: ruff
1818
args: [--fix]
1919
- id: ruff-format
2020

2121
- repo: https://github.com/pre-commit/mirrors-mypy
22-
rev: v1.8.0
22+
rev: v1.10.0
2323
hooks:
2424
- id: mypy
2525
args: [--config-file=pyproject.toml]
26-
additional_dependencies: ["sphinx", "typer[all]"]
26+
additional_dependencies: ["sphinx~=7.3", "typer[all]"]
2727
exclude: ^tests/.*\.py$

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""The configuration for this packages documentation."""
2+
23
from datetime import date
34

45
from autodoc2 import __version__

pyproject.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,26 @@ docs = [
4545
[project.scripts]
4646
autodoc2 = "autodoc2.cli:app_main"
4747

48-
[tool.ruff]
49-
extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "T20", "UP"]
48+
[tool.ruff.lint]
49+
extend-select = [
50+
"B", # flake8-bugbear
51+
"C4", # flake8-comprehensions
52+
"I", # isort
53+
"ICN", # flake8-import-conventions
54+
"ISC", # flake8-implicit-str-concat
55+
"N", # pep8-naming
56+
"PERF", # perflint (performance anti-patterns)
57+
"PGH", # pygrep-hooks
58+
"PIE", # flake8-pie
59+
"PTH", # flake8-use-pathlib
60+
"RUF", # Ruff-specific rules
61+
"SIM", # flake8-simplify
62+
"UP", # pyupgrade
63+
"T20", # flake8-print
64+
]
65+
extend-ignore = ["ISC001", "PERF203", "PGH003"]
5066

51-
[tool.ruff.per-file-ignores]
67+
[tool.ruff.lint.per-file-ignores]
5268
# ignore: Do not perform function call `typer.Option` in argument defaults
5369
"src/autodoc2/cli.py" = ["B008"]
5470
"tests/test_analyse_module.py" = ["E501"]

src/autodoc2/analysis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The core function though `analyse_module` is agnostic to the implementation,
44
It simply yields `ItemData` typed-dicts.
55
"""
6+
67
from __future__ import annotations
78

89
from dataclasses import dataclass, replace

src/autodoc2/astroid_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""Utilities for working with astroid nodes.
2-
"""
1+
"""Utilities for working with astroid nodes."""
2+
33
from __future__ import annotations
44

55
import builtins

src/autodoc2/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""CLI for the package."""
2+
23
from pathlib import Path
34
import re
45
import typing as t

src/autodoc2/config.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""The configuration for the extension."""
2+
23
from __future__ import annotations
34

45
from copy import deepcopy
@@ -151,7 +152,7 @@ def _validate_regex_list(name: str, item: t.Any) -> list[t.Pattern[str]]:
151152
try:
152153
compiled.append(re.compile(regex))
153154
except re.error as exc:
154-
raise ValidationError(f"{name}[{i}] is not a valid regex: {exc}")
155+
raise ValidationError(f"{name}[{i}] is not a valid regex: {exc}") from exc
155156
return compiled
156157

157158

@@ -168,7 +169,7 @@ def _validate_list_tuple_regex_str(
168169
try:
169170
compiled.append((re.compile(regex), replacement))
170171
except re.error as exc:
171-
raise ValidationError(f"{name}[{i}] is not a valid regex: {exc}")
172+
raise ValidationError(f"{name}[{i}] is not a valid regex: {exc}") from exc
172173
return compiled
173174

174175

@@ -217,7 +218,9 @@ def _load_regex_renderers(
217218
try:
218219
pattern = re.compile(child[0])
219220
except re.error as exc:
220-
raise ValidationError(f"{name}[{i}][0] is not a valid regex: {exc}")
221+
raise ValidationError(
222+
f"{name}[{i}][0] is not a valid regex: {exc}"
223+
) from exc
221224
klass = _load_renderer(f"{name}[{i}][1]", child[1])
222225
new.append((pattern, klass))
223226

@@ -311,24 +314,24 @@ class Config:
311314
},
312315
)
313316

314-
hidden_objects: set[
315-
t.Literal["undoc", "dunder", "private", "inherited"]
316-
] = dc.field(
317-
default_factory=lambda: {"inherited"},
318-
metadata={
319-
"help": (
320-
"The default hidden items. "
321-
"Can contain:\n"
322-
"- `undoc`: undocumented objects\n"
323-
"- `dunder`: double-underscore methods, e.g. `__str__`\n"
324-
"- `private`: single-underscore methods, e.g. `_private`\n"
325-
"- `inherited`: inherited class methods\n"
326-
),
327-
"sphinx_type": list,
328-
"sphinx_validate": _validate_hidden_objects,
329-
"doc_type": 'list["undoc" | "dunder" | "private" | "inherited"]',
330-
"category": "render",
331-
},
317+
hidden_objects: set[t.Literal["undoc", "dunder", "private", "inherited"]] = (
318+
dc.field(
319+
default_factory=lambda: {"inherited"},
320+
metadata={
321+
"help": (
322+
"The default hidden items. "
323+
"Can contain:\n"
324+
"- `undoc`: undocumented objects\n"
325+
"- `dunder`: double-underscore methods, e.g. `__str__`\n"
326+
"- `private`: single-underscore methods, e.g. `_private`\n"
327+
"- `inherited`: inherited class methods\n"
328+
),
329+
"sphinx_type": list,
330+
"sphinx_validate": _validate_hidden_objects,
331+
"doc_type": 'list["undoc" | "dunder" | "private" | "inherited"]',
332+
"category": "render",
333+
},
334+
)
332335
)
333336

334337
hidden_regexes: list[t.Pattern[str]] = dc.field(

src/autodoc2/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""A database interface for storing and querying the analysis items."""
2+
23
from __future__ import annotations
34

45
import json

src/autodoc2/render/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Convert the database items into documentation."""
2+
23
# note, for the directives and options see:
34
# https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html
45
from __future__ import annotations

src/autodoc2/render/myst_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Renderer for MyST."""
2+
23
from __future__ import annotations
34

45
import re

src/autodoc2/render/rst_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Renderer for reStructuredText."""
2+
23
from __future__ import annotations
34

45
import re

src/autodoc2/resolve_all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Handling of ``__all__`` resolution."""
2+
23
from __future__ import annotations
34

45
import typing as t

src/autodoc2/sphinx/autodoc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""autodoc directive for sphinx."""
2+
23
from __future__ import annotations
34

45
from contextlib import contextmanager

src/autodoc2/sphinx/docstring.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Directive for rendering docstrings."""
2+
23
from __future__ import annotations
34

45
from contextlib import contextmanager
@@ -34,16 +35,16 @@ def parser_options(argument: str) -> Parser | None:
3435
try:
3536
return get_parser_class(argument)
3637
except ImportError as err:
37-
raise ValueError(str(err))
38+
raise ValueError(str(err)) from err
3839

3940

4041
def summary_option(argument: str) -> int | None:
4142
"""Must be empty or a positive integer."""
4243
if argument and argument.strip():
4344
try:
4445
value = int(argument)
45-
except ValueError:
46-
raise ValueError("non-integer value; must be an integer")
46+
except ValueError as err:
47+
raise ValueError("non-integer value; must be an integer") from err
4748
if value < 0:
4849
raise ValueError("negative value; must be positive or zero")
4950
return value

src/autodoc2/sphinx/extension.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""The sphinx extension for the package."""
2+
23
from __future__ import annotations
34

45
from contextlib import suppress
@@ -47,7 +48,7 @@ def setup(app: Sphinx) -> dict[str, str | bool]:
4748
f"{CONFIG_PREFIX}{name}",
4849
field.metadata.get("sphinx_default", default),
4950
"env",
50-
types=sphinx_type,
51+
types=sphinx_type, # type: ignore[arg-type]
5152
)
5253

5354
# create the main event

src/autodoc2/sphinx/summary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Directive to generate a summary of listed objects."""
2+
23
from __future__ import annotations
34

45
from typing import Any, ClassVar

src/autodoc2/sphinx/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Handle sphinx logging."""
2+
23
from __future__ import annotations
34

45
import typing as t

src/autodoc2/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utility functions and types."""
2+
23
from __future__ import annotations
34

45
import enum
@@ -104,7 +105,7 @@ def _suffix_sort_key(s: str) -> int:
104105
for filename in filenames:
105106
if any(fnmatch(filename, m) for m in exc_files):
106107
continue
107-
name, suffix = os.path.splitext(filename)
108+
name, suffix = os.path.splitext(filename) # noqa: PTH122
108109
if suffix in extensions:
109110
to_yield.setdefault(name, []).append(suffix)
110111
root_path = Path(root)

tests/test_analyse_module.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Basic tests for the analysis module."""
2+
23
from __future__ import annotations
34

45
import typing as t

tests/test_database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests for the database."""
2+
23
from pathlib import Path
34
from textwrap import dedent
45

tests/test_render.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests for the rendering."""
2+
23
import io
34
from pathlib import Path
45
from textwrap import dedent

0 commit comments

Comments
 (0)