Skip to content
4 changes: 2 additions & 2 deletions numpydoc/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Implementing `python -m numpydoc` functionality
""" # '.' omitted at end of docstring for testing purposes!
Implements ``python -m numpydoc`` functionality.
"""

from .cli import main

Expand Down
16 changes: 13 additions & 3 deletions numpydoc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import ast
import re
from collections.abc import Sequence
from pathlib import Path
from typing import List
Expand Down Expand Up @@ -100,17 +101,19 @@ def _parse_config(s):
)
lint_parser.add_argument(
"--ignore",
type=str,
nargs="*",
help=(
Comment thread
stefanv marked this conversation as resolved.
f"""Check codes to ignore.{
"Check codes to ignore. Can be specified multiple times; each value\n"
"may contain multiple comma or space separated codes\n"
"(e.g., --ignore ES01,SA01 or --ignore ES01 --ignore 'SA01 EX01')."
f"""{
" Currently ignoring the following from "
f"{Path(project_root_from_cwd) / config_file}: {ignored_checks_text}"
"Values provided here will be in addition to the above, unless an alternate config is provided."
if ignored_checks
else ""
}"""
),
action="append",
)
lint_parser.set_defaults(func=validate_docstrings.run_hook)

Expand All @@ -123,6 +126,13 @@ def main(argv: Sequence[str] | None = None) -> int:

args = vars(ap.parse_args(argv))

# Parse --ignore=SA01,EX01
ignored_checks = []
if ignore := args.get("ignore"):
for checks in ignore:
ignored_checks += re.split("\\W+", checks)
args["ignore"] = ignored_checks

try:
func = args.pop("func")
return func(**args)
Expand Down
18 changes: 9 additions & 9 deletions numpydoc/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import importlib.resources
import inspect
import io
import sys

Expand Down Expand Up @@ -118,17 +116,19 @@ def test_validate_perfect_docstring():
assert exit_status == 0


@pytest.mark.parametrize("args", [[], ["--ignore", "SS03"]])
def test_lint(capsys, args):
with importlib.resources.path(numpydoc, "__main__.py") as fpath:
strpath = str(fpath)

argv = ["lint", strpath] + args
@pytest.mark.parametrize(
"args",
[[], ["--ignore", "SS03,ES01"], ["--ignore", "ES01", "--ignore", "SA01 SS03"]],
)
def test_lint(capsys, tmp_path, args):
f = tmp_path / "example.py"
f.write_text('"""Summary without period"""\n')
argv = ["lint", str(f)] + args
if args:
expected = ""
expected_status = 0
else:
expected = f"{strpath}:1: SS03 Summary does not end with a period"
expected = f"{f}:1: SS03 Summary does not end with a period"
expected_status = 1

return_status = numpydoc.cli.main(argv)
Expand Down
Loading