Skip to content

Commit 5cb35c1

Browse files
authored
🔧 Replace black/isort with ruff formatter (#37)
1 parent 68f917f commit 5cb35c1

File tree

14 files changed

+32
-43
lines changed

14 files changed

+32
-43
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,21 @@ 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.4.0
8+
rev: v4.5.0
99
hooks:
1010
- id: trailing-whitespace
1111
- id: end-of-file-fixer
1212
- id: check-yaml
1313

14-
- repo: https://github.com/pycqa/isort
15-
rev: 5.12.0
14+
- repo: https://github.com/astral-sh/ruff-pre-commit
15+
rev: v0.1.6
1616
hooks:
17-
- id: isort
18-
19-
- repo: https://github.com/psf/black
20-
rev: 23.1.0
21-
hooks:
22-
- id: black
23-
24-
- repo: https://github.com/charliermarsh/ruff-pre-commit
25-
rev: v0.0.249
26-
hooks:
27-
- id: ruff
17+
- id: ruff
18+
args: [--fix]
19+
- id: ruff-format
2820

2921
- repo: https://github.com/pre-commit/mirrors-mypy
30-
rev: v1.0.1
22+
rev: v1.7.1
3123
hooks:
3224
- id: mypy
3325
args: [--config-file=pyproject.toml]

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@
9595

9696
import typing as t # noqa: E402
9797

98+
from autodoc2.config import CONFIG_PREFIX, Config, PackageConfig # noqa: E402
9899
from docutils import nodes # noqa: E402
99100
from sphinx.application import Sphinx # noqa: E402
100101
from sphinx.util.docutils import SphinxDirective # noqa: E402
101102

102-
from autodoc2.config import CONFIG_PREFIX, Config, PackageConfig # noqa: E402
103-
104103

105104
def setup(app: Sphinx) -> None:
106105
app.add_object_type(

pyproject.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,17 @@ docs = [
4444
[project.scripts]
4545
autodoc2 = "autodoc2.cli:app_main"
4646

47-
[tool.isort]
48-
profile = "black"
49-
force_sort_within_sections = true
50-
5147
[tool.ruff]
52-
line-length = 110
53-
extend-select = ["B0", "C4", "ICN", "ISC", "N", "RUF", "SIM", "T20"]
48+
extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "T20", "UP"]
5449

5550
[tool.ruff.per-file-ignores]
5651
# ignore: Do not perform function call `typer.Option` in argument defaults
5752
"src/autodoc2/cli.py" = ["B008"]
5853
"tests/test_analyse_module.py" = ["E501"]
5954

55+
[tool.ruff.lint.isort]
56+
force-sort-within-sections = true
57+
6058
[tool.mypy]
6159
show_error_codes = true
6260
strict = true

src/autodoc2/analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ def yield_class_def(node: nodes.ClassDef, state: State) -> t.Iterable[ItemData]:
287287

288288
new_state = state.copy(name_stack=[*state.name_stack, node.name])
289289

290-
overridden: t.Set[str] = set() # a list of methods overridden by class inheritance
290+
overridden: set[str] = set() # a list of methods overridden by class inheritance
291291
for base in itertools.chain(iter((node,)), node.ancestors()):
292-
seen: t.Set[str] = set()
292+
seen: set[str] = set()
293293
if base.qname() in (
294294
"__builtins__.object",
295295
"builtins.object",

src/autodoc2/astroid_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def _iter_args(
589589
args: list[nodes.NodeNG],
590590
annotations: list[nodes.NodeNG],
591591
defaults: list[nodes.NodeNG],
592-
) -> t.Iterable[t.Tuple[str, None | str, str | None]]:
592+
) -> t.Iterable[tuple[str, None | str, str | None]]:
593593
"""Iterate over arguments."""
594594
default_offset = len(args) - len(defaults)
595595
packed = itertools.zip_longest(args, annotations)

src/autodoc2/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _coerce_packages(name: str, item: t.Any) -> list[PackageConfig]:
120120
return [PackageConfig(**p) for p in new]
121121

122122

123-
def _validate_replace_list(name: str, item: t.Any) -> list[t.Tuple[str, str]]:
123+
def _validate_replace_list(name: str, item: t.Any) -> list[tuple[str, str]]:
124124
"""Validate that an item is a list of tuples."""
125125
if not isinstance(item, list) or not all(
126126
isinstance(x, (list, tuple)) and len(x) == 2 for x in item

src/autodoc2/db.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def remove(self, full_name: str, descendants: bool) -> None:
3232
def __contains__(self, full_name: str) -> bool:
3333
"""Check if an item is in the database, by full_name."""
3434

35-
def get_item(self, full_name: str) -> t.Optional[ItemData]:
35+
def get_item(self, full_name: str) -> ItemData | None:
3636
"""Get an item from the database, by full_name."""
3737

3838
def get_items_like(self, full_name: str) -> t.Iterable[ItemData]:
@@ -90,8 +90,8 @@ class InMemoryDb(Database):
9090

9191
def __init__(self) -> None:
9292
"""Create the database."""
93-
self._items: t.Dict[str, ItemData] = {}
94-
self._overloads: t.Dict[str, t.List[ItemData]] = {}
93+
self._items: dict[str, ItemData] = {}
94+
self._overloads: dict[str, list[ItemData]] = {}
9595

9696
def add(self, item: ItemData) -> None:
9797
if item["type"] == "overload":
@@ -118,7 +118,7 @@ def remove(self, full_name: str, descendants: bool) -> None:
118118
def __contains__(self, full_name: str) -> bool:
119119
return full_name in self._items
120120

121-
def get_item(self, full_name: str) -> t.Optional[ItemData]:
121+
def get_item(self, full_name: str) -> ItemData | None:
122122
return self._items.get(full_name)
123123

124124
def get_items_like(self, full_name: str) -> t.Iterable[ItemData]:

src/autodoc2/render/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def warn(
6969
"""Warn the user."""
7070
self._warn(msg, type_)
7171

72-
def get_item(self, full_name: str) -> t.Optional[ItemData]:
72+
def get_item(self, full_name: str) -> ItemData | None:
7373
"""Get an item from the database, by full_name."""
7474
return self._db.get_item(full_name)
7575

src/autodoc2/sphinx/autodoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AutodocObject(SphinxDirective):
3333
has_content = True
3434

3535
# TODO autogenerate this from the config
36-
option_spec = {
36+
option_spec: t.ClassVar[dict[str, t.Any]] = {
3737
"literal": directives.flag, # return the literal render string
3838
"literal-lexer": directives.unchanged, # the lexer to use for literal
3939
}

src/autodoc2/sphinx/docstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class DocstringRenderer(SphinxDirective):
5858
required_arguments = 1 # the full name
5959
optional_arguments = 0
6060
final_argument_whitespace = True
61-
option_spec = {
61+
option_spec: t.ClassVar[dict[str, t.Any]] = {
6262
"parser": parser_options,
6363
"allowtitles": directives.flag, # used for module docstrings
6464
"summary": summary_option, # number of children to return

src/autodoc2/sphinx/extension.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def run_autodoc_package(app: Sphinx, config: Config, pkg_index: int) -> str | No
107107
return None
108108

109109
path = root_path / PurePosixPath(package.path)
110-
modules: t.Iterable[t.Tuple[Path, str]]
110+
modules: t.Iterable[tuple[Path, str]]
111111
if path.is_file():
112112
root_module = package.module or path.stem
113113
modules = [(path, root_module)]
@@ -180,7 +180,7 @@ def run_autodoc_package(app: Sphinx, config: Config, pkg_index: int) -> str | No
180180

181181
# find all the package/module, so we know what files to write
182182
LOGGER.info("[Autodoc2] Determining files to write ...")
183-
to_write: t.List[str] = []
183+
to_write: list[str] = []
184184
stack = [root_module]
185185
while stack:
186186
item = stack.pop()

src/autodoc2/sphinx/summary.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Directive to generate a summary of listed objects."""
22
from __future__ import annotations
33

4+
from typing import Any, ClassVar
5+
46
from docutils import nodes
57
from docutils.parsers.rst import directives
68
from sphinx.util.docutils import SphinxDirective
@@ -22,7 +24,7 @@ class AutodocSummary(SphinxDirective):
2224
required_arguments = 0
2325
optional_arguments = 0
2426
final_argument_whitespace = False
25-
option_spec = {
27+
option_spec: ClassVar[dict[str, Any]] = {
2628
"renderer": directives.unchanged_required,
2729
}
2830

tests/test_analyse_module.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
import typing as t
55

6-
import pytest
7-
86
from autodoc2.analysis import analyse_module
7+
import pytest
98

109

1110
def clean_item(item: dict[str, t.Any]) -> dict[str, t.Any]:

tests/test_render.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
from pathlib import Path
44
from textwrap import dedent
55

6-
import pytest
7-
from sphinx.testing.util import SphinxTestApp
8-
from sphinx.testing.util import path as sphinx_path
9-
106
from autodoc2.analysis import analyse_module
117
from autodoc2.config import Config
128
from autodoc2.db import InMemoryDb
139
from autodoc2.render.base import RendererBase
1410
from autodoc2.render.myst_ import MystRenderer
1511
from autodoc2.render.rst_ import RstRenderer
1612
from autodoc2.utils import yield_modules
13+
import pytest
14+
from sphinx.testing.util import SphinxTestApp
15+
from sphinx.testing.util import path as sphinx_path
1716

1817

1918
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)