From 29abec9556b0559f0b24e2bbf78c7a5e48edd0df Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Thu, 23 May 2024 20:11:25 -0700 Subject: [PATCH 1/2] Make `numpydoc lint --ignore ...` parsing more robust Before, the only way to specify ignores is as: numpydoc lint filename --ignore EX01 SA01 and multiple invocations of the ignore flag overwrote one another. Instead, ignored checks are now specified as: numpydoc lint --ignore=EX01,SA01 filename The comma can also be whitespace: numpydoc lint --ignore="EX01 SA01" filename Multiple ignore flags work correctly: numpydoc lint --ignore EX01 --ignore SA01 filename --- numpydoc/cli.py | 11 +++++++++-- numpydoc/tests/test_main.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/numpydoc/cli.py b/numpydoc/cli.py index ef8cff2c..37a9ab6b 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, Union @@ -100,8 +101,6 @@ def _parse_config(s): ) lint_parser.add_argument( "--ignore", - type=str, - nargs="*", help=( f"""Check codes to ignore.{ ' Currently ignoring the following from ' @@ -110,6 +109,7 @@ def _parse_config(s): if ignored_checks else '' }""" ), + action="append", ) lint_parser.set_defaults(func=validate_docstrings.run_hook) @@ -122,6 +122,13 @@ def main(argv: Union[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 12c06840..7d26737a 100644 --- a/numpydoc/tests/test_main.py +++ b/numpydoc/tests/test_main.py @@ -117,7 +117,7 @@ def test_validate_perfect_docstring(): assert exit_status == 0 -@pytest.mark.parametrize("args", [[], ["--ignore", "ES01", "SA01", "EX01"]]) +@pytest.mark.parametrize("args", [[], ["--ignore", "ES01,SA01,EX01"]]) def test_lint(capsys, args): argv = ["lint", "numpydoc/__main__.py"] + args if args: From 30de5265b9f97fd1d68db9030c19b93f11fa8373 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Wed, 19 Jun 2024 04:37:58 -0700 Subject: [PATCH 2/2] Update numpydoc/tests/test_main.py Co-authored-by: Stefanie Molin <24376333+stefmolin@users.noreply.github.com> --- numpydoc/tests/test_main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/numpydoc/tests/test_main.py b/numpydoc/tests/test_main.py index 7d26737a..f42e3964 100644 --- a/numpydoc/tests/test_main.py +++ b/numpydoc/tests/test_main.py @@ -117,7 +117,10 @@ def test_validate_perfect_docstring(): assert exit_status == 0 -@pytest.mark.parametrize("args", [[], ["--ignore", "ES01,SA01,EX01"]]) +@pytest.mark.parametrize( + "args", + [[], ["--ignore", "ES01,SA01,EX01"], ["--ignore", "ES01", "--ignore", "SA01 EX01"]], +) def test_lint(capsys, args): argv = ["lint", "numpydoc/__main__.py"] + args if args: