Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rework hook output to remove the table #611

Merged
merged 4 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
name: numpydoc-validation
description: This hook validates that docstrings in committed files adhere to numpydoc standards.
entry: numpydoc lint
require_serial: true
require_serial: false
language: python
types: [python]
27 changes: 9 additions & 18 deletions numpydoc/hooks/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from pathlib import Path
from typing import Any, Dict, List, Tuple, Union

from tabulate import tabulate

from .. import docscrape, validate
from .utils import find_project_root

Expand Down Expand Up @@ -193,7 +191,7 @@ def _get_numpydoc_issues(self, node: ast.AST) -> None:
)
self.findings.extend(
[
[f'{self.filepath}:{report["file_line"]}', name, check, description]
[f"{self.filepath}:{report['file_line']}", name, check, description]
for check, description in report["errors"]
if not self._ignore_issue(node, check)
]
Expand Down Expand Up @@ -371,19 +369,12 @@ def run_hook(
config_options = parse_config(config or project_root)
config_options["checks"] -= set(ignore or [])

findings = []
findings = False
for file in files:
findings.extend(process_file(file, config_options))

if findings:
print(
tabulate(
findings,
headers=["file", "item", "check", "description"],
tablefmt="grid",
maxcolwidths=50,
),
file=sys.stderr,
)
return 1
return 0
if file_issues := process_file(file, config_options):
findings = True

for line, obj, check, description in file_issues:
print(f"\n{line}: {check} {description}", file=sys.stderr)

return int(findings)
176 changes: 74 additions & 102 deletions numpydoc/tests/hooks/test_validate_hook.py

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions numpydoc/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,7 @@ def test_lint(capsys, args):
expected = ""
expected_status = 0
else:
expected = inspect.cleandoc(
"""
+------------------------+----------+---------+------------------------------------+
| file | item | check | description |
+========================+==========+=========+====================================+
| numpydoc/__main__.py:1 | __main__ | SS03 | Summary does not end with a period |
+------------------------+----------+---------+------------------------------------+
"""
)
expected = "numpydoc/__main__.py:1: SS03 Summary does not end with a period"
expected_status = 1

return_status = numpydoc.cli.main(argv)
Expand Down
1 change: 1 addition & 0 deletions numpydoc/tests/test_numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MockConfig:

class MockBuilder:
config = MockConfig()
_translator = None


class MockApp:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ classifiers = [
]
dependencies = [
'sphinx>=6',
'tabulate>=0.8.10',
"tomli>=1.1.0;python_version<'3.11'",
]

Expand Down
1 change: 0 additions & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
sphinx>=6
tabulate>=0.8.10
tomli>=1.1.0;python_version<'3.11'