Skip to content

Commit a36287a

Browse files
authored
Rework hook output to remove the table (#611)
* Switch from table to printed items * Remove tabulate dependency * Adjust format * Fix test after Sphinx builder change in newer version
1 parent 532cd7d commit a36287a

File tree

7 files changed

+86
-132
lines changed

7 files changed

+86
-132
lines changed

.pre-commit-hooks.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
name: numpydoc-validation
33
description: This hook validates that docstrings in committed files adhere to numpydoc standards.
44
entry: numpydoc lint
5-
require_serial: true
5+
require_serial: false
66
language: python
77
types: [python]

numpydoc/hooks/validate_docstrings.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from pathlib import Path
1515
from typing import Any, Dict, List, Tuple, Union
1616

17-
from tabulate import tabulate
18-
1917
from .. import docscrape, validate
2018
from .utils import find_project_root
2119

@@ -193,7 +191,7 @@ def _get_numpydoc_issues(self, node: ast.AST) -> None:
193191
)
194192
self.findings.extend(
195193
[
196-
[f'{self.filepath}:{report["file_line"]}', name, check, description]
194+
[f"{self.filepath}:{report['file_line']}", name, check, description]
197195
for check, description in report["errors"]
198196
if not self._ignore_issue(node, check)
199197
]
@@ -371,19 +369,12 @@ def run_hook(
371369
config_options = parse_config(config or project_root)
372370
config_options["checks"] -= set(ignore or [])
373371

374-
findings = []
372+
findings = False
375373
for file in files:
376-
findings.extend(process_file(file, config_options))
377-
378-
if findings:
379-
print(
380-
tabulate(
381-
findings,
382-
headers=["file", "item", "check", "description"],
383-
tablefmt="grid",
384-
maxcolwidths=50,
385-
),
386-
file=sys.stderr,
387-
)
388-
return 1
389-
return 0
374+
if file_issues := process_file(file, config_options):
375+
findings = True
376+
377+
for line, obj, check, description in file_issues:
378+
print(f"\n{line}: {check} {description}", file=sys.stderr)
379+
380+
return int(findings)

numpydoc/tests/hooks/test_validate_hook.py

+74-102
Large diffs are not rendered by default.

numpydoc/tests/test_main.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,7 @@ def test_lint(capsys, args):
124124
expected = ""
125125
expected_status = 0
126126
else:
127-
expected = inspect.cleandoc(
128-
"""
129-
+------------------------+----------+---------+------------------------------------+
130-
| file | item | check | description |
131-
+========================+==========+=========+====================================+
132-
| numpydoc/__main__.py:1 | __main__ | SS03 | Summary does not end with a period |
133-
+------------------------+----------+---------+------------------------------------+
134-
"""
135-
)
127+
expected = "numpydoc/__main__.py:1: SS03 Summary does not end with a period"
136128
expected_status = 1
137129

138130
return_status = numpydoc.cli.main(argv)

numpydoc/tests/test_numpydoc.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class MockConfig:
3636

3737
class MockBuilder:
3838
config = MockConfig()
39+
_translator = None
3940

4041

4142
class MockApp:

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ classifiers = [
2929
]
3030
dependencies = [
3131
'sphinx>=6',
32-
'tabulate>=0.8.10',
3332
"tomli>=1.1.0;python_version<'3.11'",
3433
]
3534

requirements/default.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Generated via tools/generate_requirements.py and pre-commit hook.
22
# Do not edit this file; modify pyproject.toml instead.
33
sphinx>=6
4-
tabulate>=0.8.10
54
tomli>=1.1.0;python_version<'3.11'

0 commit comments

Comments
 (0)