pydocstyle icon indicating copy to clipboard operation
pydocstyle copied to clipboard

Files passed as arguments ignored by --match

Open jpulec opened this issue 9 years ago • 11 comments

It looks like when you pass specific filenames to pep257, it ignores if you have set the --match option.

For example:

pep257 foo.py bar.py --match='(?!foo).*\.py'

Will still check foo.py and bar.py. While I understand why this makes sense, since there is a default match pattern that ignores 'test_.', and you want to be able to easily use pep257 on a file prefixed with 'test._' if desired, iit means that pep257 doesn't perform as one might expect when using something like xargs to pass a bunch of files into it.

jpulec avatar Mar 12 '15 05:03 jpulec

PR in #112

jpulec avatar Mar 12 '15 05:03 jpulec

Close?

jayvdb avatar May 01 '15 06:05 jayvdb

Is this seen as a non-standard use case, or that it breaks expected behavior?

jpulec avatar May 01 '15 18:05 jpulec

I'm not sure how I feel about this. On the one hand, I get your point, but I also feel that passing an explicit file name should take precedence over the matching regex. Anyone else cares to pitch in?

Nurdok avatar May 02 '15 14:05 Nurdok

Was this reverted? The behavior I am seeing shows that an explicitly passed in file will override match

erichiller avatar Nov 18 '17 19:11 erichiller

AFAIK if it overrides match it will generate conflicts when using git pre-commit hook.

xmnlab avatar Oct 22 '19 04:10 xmnlab

I'm noticing it indeed overrides match and match_dir configs when using the pre-commit hook since the files are passed as positional arguments. Which makes the hook useless as far as I can tell because it checks files which are meant to be ignored.

A workaround is to use a local hook to run the shell command directly, which allows to use your project configuration in a consistent way:

- repo: local
  hooks:
    - id: pydocstyle
      name: pydocstyle
      types: [python]
      entry: pydocstyle
      language: system
      pass_filenames: false

aaaaahaaaaa avatar Jan 17 '20 18:01 aaaaahaaaaa

On the one hand, I get your point, but I also feel that passing an explicit file name should take precedence over the matching regex. Anyone else cares to pitch in?

Currently the only way to exclude certain files is using negative lookahead patterns like --match='(?!test_).*\.py'. Since this is ignored when files are passed in (i.e. when using pre-commit) there is no way to exclude files passed in on the CLI.

If you're using pydocstyles pre-commit support, you'll be passing in the list of changed files every time you do a git commit, but you will still want to exclude certain files, which this issue prevents. The only thing pre-commit users can do is use pass_filenames: false (as suggested in previous comment) which causes pydocstyle to run on the whole codebase. But in a large codebase, this is too slow.

IMHO, for the pre-commit support to be useful, there needs to be a way to exclude certain file patterns, even if they are passed in explicitly on the CLI.

What if we introduced a switch that prevents match from being ignored when filenames are passed in? That would retain backwards compatibility, but bring joy back into the life of pydocstyle/pre-commit users.

danmoz avatar Aug 23 '21 07:08 danmoz

Has this behavior changed again? I'm trying to reproduce a configuration problem, and I am finding that pydocstyle honors the match option in pyproject.toml even when I pass a filename on the command line.

With this config:

[tool.pydocstyle]
match = '.*\.py'

pydocstyle does check my tests:

$ pydocstyle tests/test_pmf.py
tests/test_pmf.py:16 in public class `TestPMFInit`:
        D101: Missing docstring in public class

but with the default config, pydocstyle 6.2.3 is ignoring unmatched files even when I list them explicitly on the command line:

$ pydocstyle tests/test_pmf.py
# OK

bszonye avatar Jan 08 '23 20:01 bszonye

After a bit of digging, I believe that this issue was resolved by #550 (released in version 6.2.0).

If I revert to pydocstyle 6.1.1, I see inconsistent behavior depending on whether the command-line argument is a filename or a path:

$ pydocstyle ./test_pmf.py
./test_pmf.py:16 in public class `TestPMFInit`:
        D101: Missing docstring in public class
$ pydocstyle test_pmf.py
# OK

After #550, those two cases behave the same:

$ pydocstyle ./test_pmf.py
# OK
$ pydocstyle test_pmf.py
# OK

Therefore, I think this issue can be closed. This also means that the reverted change in #610 wasn't actually necessary (which is good, because of the performance concerns mentioned by @danmoz).

bszonye avatar Jan 08 '23 21:01 bszonye

Thanks for digging @bszonye

Perhaps out of scope but a similar issue with --match-dir is an issue for me before I can start using pydocstyle with pre-commit:

$ pydocstyle baz/test.py --match-dir='(?!baz).*' -v 

Checking file baz/test.py.

I would not expect test.py to be checked given the --match-dir parameter.

danmoz avatar Jan 08 '23 22:01 danmoz