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

Does not respect exclude if excluded file is passed as parameter #53

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

Does not respect exclude if excluded file is passed as parameter #53

asottile opened this issue Apr 3, 2021 · 11 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @cabello on Oct 31, 2014, 08:01

If I run:

flake8 --config=private/lint/flake8-hook.ini django_app/migrations/0010_freeze.py

And my flake8-hook.ini contains:

[flake8]
exclude = django_app/migrations

Flake ignores the passed configuration and lints the file passed as parameter.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Oct 31, 2014, 08:13

This is intentional. Some people want to forcibly check a file that is otherwise excluded. This would be a bug if you instead ran:

flake8 --config=private/lint/flake8-hook.ini django_app

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @cabello on Oct 31, 2014, 09:45

Is there an alternative besides applying the exclusion policy myself?

I am getting the list of files from bash in a commit hook: py_files=$(git diff --cached --name-only --diff-filter=ACM | grep ".py$");

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Oct 31, 2014, 10:12

Why aren't you using flake8's commit hook. I'm pretty sure it already handles this.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @cabello on Oct 31, 2014, 13:18

I managed to make it working following your suggestion, instead of checking for files, I am checking for the changed folders, worked out nicely.

I am not sure why we are not using flake8 built-in commit hook though. =/

Thanks for the quick and prompt reply & help!

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 1, 2014, 18:18

Always happy to help @cabello !

Thanks for reporting this anyway

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @dwaynebailey on Apr 28, 2016, 19:52

I'm using pre-commit and while this behaviour might be intentional it is actually massively inconsistent and undocumented.

If I supply --config to override any default config I really don't expect it to behave differently regardless of what I supply. If I supply dir/ it respects it, if I supply dir/file.py it doesn't.

It's also selectively takes configuration from my setup.cfg:

  • Its takes max-line-length= and statistics=
  • But ignores exclude= and ignore=

I'm sure there's a more logical way to say ignore my settings?

Current behaviour is full settings for dir/ or default, half settings for specified file.py. Pretty confusing tbh.

In the interest of those who come after. This pre-commit issue suggests some workarounds.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Apr 29, 2016, 05:46

Hi @dwaynebailey,

At the present time, all configuration file discovery, parsing, and management is handled by pycodestyle (formerly pep8). Flake8 3.0 has taken control of this aspect and now handles this on its own and has fixed the problem I think you are describing (where you expect --config to ignore all other config files on disk) while providing alternative methods for retaining the existing behaviour.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @davecremins on Dec 15, 2016, 06:29

This should not have been closed, this is still an issue in flake8 3.0.4

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @thejcannon on Jan 31, 2020, 09:34

Has any thought been given to "solving" this issue in the same way isort has? By adding a flag that tells the tool to "force" the exclusions, even on cmd-line args. (See filter_files in the docs).

It's truly unfortunate to have to specify the exclusions in more than one place: The config file (pyproject.toml or otherwise) for tooling running on the code as a directory, and then one for each config file that controls a tool that runs on the code per-file (like pre-commit).

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Jan 31, 2020, 09:36

afaict this got "fixed" at some point:

[flake8]
exclude = t.py
import os
$ flake8 t.py
$

though I suspect it was on accident

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @thejcannon on Jan 31, 2020, 09:54

Looks like that behavior is documented in issue 392, and the "bug" (un)fortunately doesn't apply to exclusion directories, just exclusion filenames. In my use case, there are several files in the directory, so I'm still out of luck 🤷

@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
Projects
None yet
Development

No branches or pull requests

1 participant