Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Files passed as arguments ignored by --match #111

Open
jpulec opened this issue Mar 12, 2015 · 11 comments
Open

Files passed as arguments ignored by --match #111

jpulec opened this issue Mar 12, 2015 · 11 comments

Comments

@jpulec
Copy link

jpulec commented Mar 12, 2015

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
Copy link
Author

jpulec commented Mar 12, 2015

PR in #112

@jayvdb
Copy link
Member

jayvdb commented May 1, 2015

Close?

@jpulec
Copy link
Author

jpulec commented May 1, 2015

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

@Nurdok
Copy link
Member

Nurdok commented May 2, 2015

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?

@erichiller
Copy link

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

@xmnlab
Copy link

xmnlab commented Oct 22, 2019

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

toryhaavik pushed a commit to ibis-project/ibis that referenced this issue Oct 29, 2019
In this PR:    - Fixed omniscidb docstrings  - Fixed some docstrings
- Added pydocstyle check for ./ibis/.py and ./ibis/omniscidb/*.py
Current issues with pydocstyle:    -
PyCQA/pydocstyle#111  -
PyCQA/pydocstyle#363
Author: Ivan Ogasawara <ivan.ogasawara@gmail.com>

Closes #1996 from xmnlab/add-docstring-check and squashes the following commits:

bcda303 [Ivan Ogasawara] Fixed pydocstyle command.
55ff381 [Ivan Ogasawara] Add pydocstyle match-dir parameter into CI recipe.
5b270e8 [Ivan Ogasawara] Add docstring check to CI and git pre-commit hook
@aaaaahaaaaa
Copy link

aaaaahaaaaa commented Jan 17, 2020

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

@danmoz
Copy link

danmoz commented Aug 23, 2021

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.

@bszonye
Copy link

bszonye commented Jan 8, 2023

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
Copy link

bszonye commented Jan 8, 2023

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).

@danmoz
Copy link

danmoz commented Jan 8, 2023

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants