diff --git a/numpydoc/__main__.py b/numpydoc/__main__.py index 8cd0943e..c3fb1ec5 100644 --- a/numpydoc/__main__.py +++ b/numpydoc/__main__.py @@ -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 diff --git a/numpydoc/cli.py b/numpydoc/cli.py index 30daa3f5..d72b7e0c 100644 --- a/numpydoc/cli.py +++ b/numpydoc/cli.py @@ -2,6 +2,7 @@ import argparse import ast +import re from collections.abc import Sequence from pathlib import Path from typing import List @@ -100,10 +101,11 @@ def _parse_config(s): ) lint_parser.add_argument( "--ignore", - type=str, - nargs="*", help=( - 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." @@ -111,6 +113,7 @@ def _parse_config(s): else "" }""" ), + action="append", ) lint_parser.set_defaults(func=validate_docstrings.run_hook) @@ -123,6 +126,13 @@ def main(argv: Sequence[str] | None = None) -> int: args = vars(ap.parse_args(argv)) + # Parse --ignored=SA01,EX01 + ignored_checks = [] + if args.get("ignore", None) is not None: + for checks in args["ignore"]: + ignored_checks += re.split("\\W+", checks) + args["ignore"] = ignored_checks + try: func = args.pop("func") return func(**args) diff --git a/numpydoc/tests/test_main.py b/numpydoc/tests/test_main.py index 12a5a086..c2dc9be8 100644 --- a/numpydoc/tests/test_main.py +++ b/numpydoc/tests/test_main.py @@ -1,5 +1,3 @@ -import importlib.resources -import inspect import io import sys @@ -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)