Skip to content

Commit

Permalink
馃敡 Update pre-commit (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed May 13, 2024
1 parent 19587f0 commit 1f55a88
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.8"
- uses: pre-commit/action@v3.0.0
python-version: "3.9"
- uses: pre-commit/action@v3.0.1

tests:

Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ exclude: ^tests/.*\.md|tests/.*\.rst|tests/.*\.xml|docs/apidocs/.*

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.4.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.10.0
hooks:
- id: mypy
args: [--config-file=pyproject.toml]
additional_dependencies: ["sphinx", "typer[all]"]
additional_dependencies: ["sphinx~=7.3", "typer[all]"]
exclude: ^tests/.*\.py$
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The configuration for this packages documentation."""

from datetime import date

from autodoc2 import __version__
Expand Down
22 changes: 19 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,26 @@ docs = [
[project.scripts]
autodoc2 = "autodoc2.cli:app_main"

[tool.ruff]
extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "T20", "UP"]
[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
"PERF", # perflint (performance anti-patterns)
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PTH", # flake8-use-pathlib
"RUF", # Ruff-specific rules
"SIM", # flake8-simplify
"UP", # pyupgrade
"T20", # flake8-print
]
extend-ignore = ["ISC001", "PERF203", "PGH003"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# ignore: Do not perform function call `typer.Option` in argument defaults
"src/autodoc2/cli.py" = ["B008"]
"tests/test_analyse_module.py" = ["E501"]
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The core function though `analyse_module` is agnostic to the implementation,
It simply yields `ItemData` typed-dicts.
"""

from __future__ import annotations

from dataclasses import dataclass, replace
Expand Down
4 changes: 2 additions & 2 deletions src/autodoc2/astroid_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Utilities for working with astroid nodes.
"""
"""Utilities for working with astroid nodes."""

from __future__ import annotations

import builtins
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""CLI for the package."""

from pathlib import Path
import re
import typing as t
Expand Down
45 changes: 24 additions & 21 deletions src/autodoc2/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The configuration for the extension."""

from __future__ import annotations

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


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


Expand Down Expand Up @@ -217,7 +218,9 @@ def _load_regex_renderers(
try:
pattern = re.compile(child[0])
except re.error as exc:
raise ValidationError(f"{name}[{i}][0] is not a valid regex: {exc}")
raise ValidationError(
f"{name}[{i}][0] is not a valid regex: {exc}"
) from exc
klass = _load_renderer(f"{name}[{i}][1]", child[1])
new.append((pattern, klass))

Expand Down Expand Up @@ -311,24 +314,24 @@ class Config:
},
)

hidden_objects: set[
t.Literal["undoc", "dunder", "private", "inherited"]
] = dc.field(
default_factory=lambda: {"inherited"},
metadata={
"help": (
"The default hidden items. "
"Can contain:\n"
"- `undoc`: undocumented objects\n"
"- `dunder`: double-underscore methods, e.g. `__str__`\n"
"- `private`: single-underscore methods, e.g. `_private`\n"
"- `inherited`: inherited class methods\n"
),
"sphinx_type": list,
"sphinx_validate": _validate_hidden_objects,
"doc_type": 'list["undoc" | "dunder" | "private" | "inherited"]',
"category": "render",
},
hidden_objects: set[t.Literal["undoc", "dunder", "private", "inherited"]] = (
dc.field(
default_factory=lambda: {"inherited"},
metadata={
"help": (
"The default hidden items. "
"Can contain:\n"
"- `undoc`: undocumented objects\n"
"- `dunder`: double-underscore methods, e.g. `__str__`\n"
"- `private`: single-underscore methods, e.g. `_private`\n"
"- `inherited`: inherited class methods\n"
),
"sphinx_type": list,
"sphinx_validate": _validate_hidden_objects,
"doc_type": 'list["undoc" | "dunder" | "private" | "inherited"]',
"category": "render",
},
)
)

hidden_regexes: list[t.Pattern[str]] = dc.field(
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A database interface for storing and querying the analysis items."""

from __future__ import annotations

import json
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/render/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Convert the database items into documentation."""

# note, for the directives and options see:
# https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html
from __future__ import annotations
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/render/myst_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Renderer for MyST."""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/render/rst_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Renderer for reStructuredText."""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/resolve_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Handling of ``__all__`` resolution."""

from __future__ import annotations

import typing as t
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/sphinx/autodoc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""autodoc directive for sphinx."""

from __future__ import annotations

from contextlib import contextmanager
Expand Down
7 changes: 4 additions & 3 deletions src/autodoc2/sphinx/docstring.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Directive for rendering docstrings."""

from __future__ import annotations

from contextlib import contextmanager
Expand Down Expand Up @@ -34,16 +35,16 @@ def parser_options(argument: str) -> Parser | None:
try:
return get_parser_class(argument)
except ImportError as err:
raise ValueError(str(err))
raise ValueError(str(err)) from err


def summary_option(argument: str) -> int | None:
"""Must be empty or a positive integer."""
if argument and argument.strip():
try:
value = int(argument)
except ValueError:
raise ValueError("non-integer value; must be an integer")
except ValueError as err:
raise ValueError("non-integer value; must be an integer") from err
if value < 0:
raise ValueError("negative value; must be positive or zero")
return value
Expand Down
3 changes: 2 additions & 1 deletion src/autodoc2/sphinx/extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The sphinx extension for the package."""

from __future__ import annotations

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

# create the main event
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/sphinx/summary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Directive to generate a summary of listed objects."""

from __future__ import annotations

from typing import Any, ClassVar
Expand Down
1 change: 1 addition & 0 deletions src/autodoc2/sphinx/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Handle sphinx logging."""

from __future__ import annotations

import typing as t
Expand Down
3 changes: 2 additions & 1 deletion src/autodoc2/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utility functions and types."""

from __future__ import annotations

import enum
Expand Down Expand Up @@ -104,7 +105,7 @@ def _suffix_sort_key(s: str) -> int:
for filename in filenames:
if any(fnmatch(filename, m) for m in exc_files):
continue
name, suffix = os.path.splitext(filename)
name, suffix = os.path.splitext(filename) # noqa: PTH122
if suffix in extensions:
to_yield.setdefault(name, []).append(suffix)
root_path = Path(root)
Expand Down
1 change: 1 addition & 0 deletions tests/test_analyse_module.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Basic tests for the analysis module."""

from __future__ import annotations

import typing as t
Expand Down
1 change: 1 addition & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the database."""

from pathlib import Path
from textwrap import dedent

Expand Down
1 change: 1 addition & 0 deletions tests/test_render.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the rendering."""

import io
from pathlib import Path
from textwrap import dedent
Expand Down

0 comments on commit 1f55a88

Please sign in to comment.