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

feature request: --force-exclude #368

Closed
asottile opened this issue Apr 3, 2021 · 4 comments
Closed

feature request: --force-exclude #368

asottile opened this issue Apr 3, 2021 · 4 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @neutrinoceros on Dec 28, 2020, 07:29

Please describe how you installed Flake8

$ pip install flake8

Please provide the exact, unmodified output of flake8 --bug-report

{
"dependencies": [],
"platform": {
"python_implementation": "CPython",
"python_version": "3.8.6",
"system": "Darwin"
},
"plugins": [
{
"is_local": false,
"plugin": "flake8-bugbear",
"version": "20.11.1"
},
{
"is_local": false,
"plugin": "mccabe",
"version": "0.6.1"
},
{
"is_local": false,
"plugin": "pycodestyle",
"version": "2.6.0"
},
{
"is_local": false,
"plugin": "pyflakes",
"version": "2.2.0"
}
],
"version": "3.8.4"
}

Please describe the problem or feature

I am trying to setup pre-commit-ci with a pre-commit hook for flake8. The problem I'm having is that the target project uses flake8's exclude flag (as configured in setup.cfg).
Because pre-commit-ci is running hooks against every file however (pre-commit run --all-files), this exclude list is de facto ignored and errors are being reported that we do not care about.
A similar problem is solved for black as of version 20.8b0 (see https://black.readthedocs.io/en/stable/change_log.html#b0) with the introduction of a --force-exclude flag which takes priority over pre-commit's --all-files. I would like to propose that a similar flag be added to flake8.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Dec 28, 2020, 07:46

Soon: Feature request on pre-commit "I want a 'no really all-files' option to override Flake8 and Black's --force-exclude options"

More seriously, this seems like a ridiculous escalation of tools fighting each other. Looking at the original black issue: psf/black#438 (comment) I can guess how @asottile will react to this (positively).

Personally, if we're going to do this, I'd rather just cut a v4 that changes the behaviour of --exclude rather than compound flags upon flags upon flags that seem contradictory/unnecessary/confusing in their naming and purpose.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @neutrinoceros on Dec 28, 2020, 07:53

Personally, if we're going to do this, I'd rather just cut a v4 that changes the behaviour of --exclude rather than compound flags upon flags upon flags that seem contradictory/unnecessary/confusing in their naming and purpose.

Honestly that would feel much better to me too ! I should note that I'm willing to contribute a patch for this, if you guys can agree on what feels like the most reasonable option. Of course I'm curious to read what @asottile thinks of this as a maintainer/creator of both conflicting tools.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Dec 28, 2020, 08:40

I've kinda changed my mind after thinking about this more. You're asking all the tools involved to do a bunch of extra work when you've misconfigured them in the first place. There's an easy solution which is to use exclude: from pre-commit. That was actually most of the reason for creating pre-commit was to prevent each and every tool from needing to implement inclusion / exclusion / recursion (because it's hard / impossible to please everyone here and each tool does this slightly differently)

The other thing I've noticed is flake8 already does what you want so you'll want to provide more information including an actual reproduction:

$ echo -e $'[flake8]\nexclude=t.py' > setup.cfg
$ echo 'import os' > t.py
$ flake8 t.py
$ echo $?
0

you can also use per-file-ignores to accomplish what you want as well -- this will act like force-exclude

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @neutrinoceros on Dec 28, 2020, 09:38

Thanks a lot @asottile, indeed exclude: from pre-commit is exactly what I was looking for. It solves the problem I was reporting and more.

@asottile asottile closed this as completed Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant