Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make numpydoc lint --ignore ... parsing more robust #560

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 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, Union
Expand Down Expand Up @@ -100,8 +101,6 @@ def _parse_config(s):
)
lint_parser.add_argument(
"--ignore",
type=str,
nargs="*",
help=(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should indicate how this can be used in the help now that there are multiple options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanv WDYT?

f"""Check codes to ignore.{
' Currently ignoring the following from '
Expand All @@ -110,6 +109,7 @@ def _parse_config(s):
if ignored_checks else ''
}"""
),
action="append",
)
lint_parser.set_defaults(func=validate_docstrings.run_hook)

Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion numpydoc/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down