Skip to content

Commit acad4ec

Browse files
Use ruff for linting and formatting (#555)
2 parents eece14b + 2e6d88b commit acad4ec

22 files changed

+208
-204
lines changed

.git-blame-ignore-revs

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
4b38c01e680cf2032acb09819bc0985e5dfc5ca8
2+
be316333f436519e0e2ab1379cbdedde79c9ac68

.pre-commit-config.yaml

+5-14
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,19 @@ repos:
1717
- id: mixed-line-ending
1818
- id: trailing-whitespace
1919

20-
- repo: https://github.com/psf/black
21-
rev: 3702ba224ecffbcec30af640c149f231d90aebdb # frozen: 24.4.2
22-
hooks:
23-
- id: black
24-
2520
- repo: https://github.com/pre-commit/mirrors-prettier
2621
rev: ffb6a759a979008c0e6dff86e39f4745a2d9eac4 # frozen: v3.1.0
2722
hooks:
2823
- id: prettier
2924
types_or: [yaml, toml, markdown, css, scss, javascript, json]
3025
args: [--prose-wrap=preserve]
3126

32-
- repo: https://github.com/adamchainz/blacken-docs
33-
rev: 960ead214cd1184149d366c6d27ca6c369ce46b6 # frozen: 1.16.0
34-
hooks:
35-
- id: blacken-docs
36-
37-
- repo: https://github.com/asottile/pyupgrade
38-
rev: 12af25eb252deaaecb6b259df40d01f42e716dc3 # frozen: v3.15.2
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: "f8a3f8c471fb698229face5ed7640a64900b781e" # frozen: v0.4.4
3929
hooks:
40-
- id: pyupgrade
41-
args: [--py38-plus]
30+
- id: ruff
31+
args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"]
32+
- id: ruff-format
4233

4334
- repo: local
4435
hooks:

doc/conf.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
# list see the documentation:
55
# https://www.sphinx-doc.org/en/master/usage/configuration.html
66

7-
from datetime import date
8-
import numpydoc
9-
107
# -- Path setup --------------------------------------------------------------
11-
128
# If extensions (or modules to document with autodoc) are in another directory,
139
# add these directories to sys.path here. If the directory is relative to the
1410
# documentation root, use os.path.abspath to make it absolute, like shown here.
15-
1611
import os
1712
import sys
13+
from datetime import date
14+
15+
import numpydoc
1816

1917
# for example.py
2018
sys.path.insert(0, os.path.abspath("."))

doc/example.py

-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,3 @@ def foo(var1, var2, *args, long_var_name="hi", only_seldom_used_keyword=0, **kwa
127127
# separate following codes (according to PEP257).
128128
# But for function, method and module, there should be no blank lines
129129
# after closing the docstring.
130-
pass

numpydoc/cli.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import argparse
44
import ast
5+
from collections.abc import Sequence
56
from pathlib import Path
6-
from typing import List, Sequence, Union
7+
from typing import List, Union
78

89
from .docscrape_sphinx import get_doc_object
910
from .hooks import utils, validate_docstrings

numpydoc/docscrape.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
"""Extract reference documentation from the NumPy source tree.
2-
3-
"""
1+
"""Extract reference documentation from the NumPy source tree."""
42

3+
import copy
54
import inspect
6-
import textwrap
7-
import re
85
import pydoc
9-
from warnings import warn
6+
import re
7+
import sys
8+
import textwrap
109
from collections import namedtuple
1110
from collections.abc import Callable, Mapping
12-
import copy
13-
import sys
14-
1511
from functools import cached_property
12+
from warnings import warn
1613

1714

1815
def strip_blank_lines(l):

numpydoc/docscrape_sphinx.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import re
21
import inspect
3-
import textwrap
4-
import pydoc
5-
from collections.abc import Callable
62
import os
3+
import pydoc
4+
import re
5+
import textwrap
76

87
from jinja2 import FileSystemLoader
98
from jinja2.sandbox import SandboxedEnvironment
10-
import sphinx
119
from sphinx.jinja2glue import BuiltinTemplateLoader
1210

13-
from .docscrape import NumpyDocString, FunctionDoc, ClassDoc, ObjDoc
11+
from .docscrape import ClassDoc, FunctionDoc, NumpyDocString, ObjDoc
1412
from .docscrape import get_doc_object as get_doc_object_orig
1513
from .xref import make_xref
1614

17-
1815
IMPORT_MATPLOTLIB_RE = r"\b(import +matplotlib|from +matplotlib +import)\b"
1916

2017

numpydoc/hooks/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import itertools
44
import os
5+
from collections.abc import Sequence
56
from pathlib import Path
6-
from typing import Sequence
77

88

99
def find_project_root(srcs: Sequence[str]):
@@ -31,7 +31,7 @@ def find_project_root(srcs: Sequence[str]):
3131
`Black <https://github.com/psf/black/blob/main/src/black/files.py>`_.
3232
"""
3333
if not srcs:
34-
return Path(".").resolve(), "current directory"
34+
return Path().resolve(), "current directory"
3535

3636
common_path = Path(
3737
os.path.commonpath([Path(src).expanduser().resolve() for src in srcs])

numpydoc/numpydoc.py

+23-19
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,22 @@
1717
1818
"""
1919

20-
from copy import deepcopy
21-
import re
22-
import pydoc
23-
import inspect
24-
from collections.abc import Callable
2520
import hashlib
21+
import inspect
2622
import itertools
23+
import pydoc
24+
import re
25+
from collections.abc import Callable
26+
from copy import deepcopy
2727

28-
from docutils.nodes import citation, Text, section, comment, reference, inline
29-
import sphinx
30-
from sphinx.addnodes import pending_xref, desc_content
28+
from docutils.nodes import Text, citation, comment, inline, reference, section
29+
from sphinx.addnodes import desc_content, pending_xref
3130
from sphinx.util import logging
32-
from sphinx.errors import ExtensionError
3331

32+
from . import __version__
3433
from .docscrape_sphinx import get_doc_object
35-
from .validate import validate, ERROR_MSGS, get_validation_checks
34+
from .validate import get_validation_checks, validate
3635
from .xref import DEFAULT_LINKS
37-
from . import __version__
3836

3937
logger = logging.getLogger(__name__)
4038

@@ -248,10 +246,10 @@ def mangle_signature(app, what, name, obj, options, sig, retann):
248246
return "", ""
249247

250248
if not (isinstance(obj, Callable) or hasattr(obj, "__argspec_is_invalid_")):
251-
return
249+
return None
252250

253251
if not hasattr(obj, "__doc__"):
254-
return
252+
return None
255253
doc = get_doc_object(obj, config={"show_class_members": False})
256254
sig = doc["Signature"] or _clean_text_signature(
257255
getattr(obj, "__text_signature__", None)
@@ -275,7 +273,7 @@ def _clean_text_signature(sig):
275273

276274
def setup(app, get_doc_object_=get_doc_object):
277275
if not hasattr(app, "add_config_value"):
278-
return # probably called by nose, better bail out
276+
return None # probably called by nose, better bail out
279277

280278
global get_doc_object
281279
get_doc_object = get_doc_object_
@@ -417,12 +415,18 @@ def match_items(lines, content_old):
417415
418416
Examples
419417
--------
420-
>>> lines = ['', 'A', '', 'B', ' ', '', 'C', 'D']
421-
>>> lines_old = ['a', '', '', 'b', '', 'c']
422-
>>> items_old = [('file1.py', 0), ('file1.py', 1), ('file1.py', 2),
423-
... ('file2.py', 0), ('file2.py', 1), ('file2.py', 2)]
418+
>>> lines = ["", "A", "", "B", " ", "", "C", "D"]
419+
>>> lines_old = ["a", "", "", "b", "", "c"]
420+
>>> items_old = [
421+
... ("file1.py", 0),
422+
... ("file1.py", 1),
423+
... ("file1.py", 2),
424+
... ("file2.py", 0),
425+
... ("file2.py", 1),
426+
... ("file2.py", 2),
427+
... ]
424428
>>> content_old = ViewList(lines_old, items=items_old)
425-
>>> match_items(lines, content_old) # doctest: +NORMALIZE_WHITESPACE
429+
>>> match_items(lines, content_old) # doctest: +NORMALIZE_WHITESPACE
426430
[('file1.py', 0), ('file1.py', 0), ('file2.py', 0), ('file2.py', 0),
427431
('file2.py', 2), ('file2.py', 2), ('file2.py', 2), ('file2.py', 2)]
428432
>>> # first 2 ``lines`` are matched to 'a', second 2 to 'b', rest to 'c'

numpydoc/tests/hooks/example_module.py

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
def some_function(name):
55
"""Welcome to some function."""
6-
pass
76

87

98
class MyClass:
@@ -23,11 +22,9 @@ def do_something(self, *args, **kwargs):
2322
----------
2423
*args
2524
"""
26-
pass
2725

2826
def process(self):
2927
"""Process stuff."""
30-
pass
3128

3229

3330
class NewClass:

0 commit comments

Comments
 (0)