Repository navigation
Conversation
-i/--ignore used action=append, so a second path passed to the same flag was consumed as a positional argument and reported as a missing path. Three neighbouring options of the same parser (--enable, --disable, --sort-by) already accept comma-separated values, so this makes --ignore behave the same way while still accumulating across repeated flags. An empty value is now dropped instead of being kept: the empty string is a substring of every path, so -i '' silently ignored the whole run. Fixes sphinx-contrib#113
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
hugovk
left a comment
There was a problem hiding this comment.
I did not use
nargs="+", which the reporter suggested: with a greedynargs,sphinx-lint -i d1 .would swallow the positional path as a second ignore value, so the command would lint nothing at all. The comma keeps the option and the positional arguments separable, and it matches what the rest of the parser already does.
Good point.
Although splitting a comma-separated string means you can no longer ignore a path with a comma in it: --ignore abc,def ignores abc and def, but won't ignore a abc,def/ directory.
Do we care about this?
| @@ -0,0 +1,53 @@ | |||
| """Tests for issue #113: ``--ignore`` should accept a list of paths.""" | |||
There was a problem hiding this comment.
No need to reference the issue number here or in the test filename. Call it test_ignore.py?
This file doesn't need to be executable.
There was a problem hiding this comment.
Also these tests could be in a single test function using @pytest.mark.parametrize.
There was a problem hiding this comment.
And give an example in the README?
| @pytest.fixture | ||
| def tree(tmp_path): | ||
| """Build a tree with two ignorable subdirs, each holding a faulty file.""" | ||
| for name in ("d1", "d2"): |
There was a problem hiding this comment.
A macOS temp dir can be like /var/folders/p6/lf2s1s5d4kb335g2d1td8z8c0000gn/T which can match d1.
Let's rename these throughout, perhaps something like:
| for name in ("d1", "d2"): | |
| for name in ("ignored_dir1", "ignored_dir2"): |
Fixes #113.
-i/--ignoreis declared withaction="append", so it takes exactly one value per flag. A second path handed to the same flag falls through to the positional argument list and is then reported as a path that does not exist:Three neighbouring options of the same parser —
--enable,--disableand--sort-by— already take comma-separated values, so--ignorenow does the same through a smallExtendIgnoreAction, while still accumulating across repeated flags. Both spellings work and can be mixed:I did not use
nargs="+", which the reporter suggested: with a greedynargs,sphinx-lint -i d1 .would swallow the positional path as a second ignore value, so the command would lint nothing at all. The comma keeps the option and the positional arguments separable, and it matches what the rest of the parser already does.A second defect fell out of this
Today an empty value silences the entire run:
walk()skips a path when an ignored value is a substring of it, and the empty string is a substring of every path. Empty values are now dropped, so-i ""is a no-op rather than a global mute. That is one of the four tests.Measured
On
c6d82b7:The two that fail before the fix are the comma-separated list and the empty value; the other two cover a single
-iand repeated-iflags, which already worked and must keep working.ruff checkandruff format --checkat the pinned v0.15.20 are clean on both changed files, andruff checkis equally clean on an untouched checkout. The man page entry for-iis updated to match.AI-assisted (LLM used for drafting); the runs above are mine.