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

Pre-commit hook doesn't respect configuration files #155

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

Pre-commit hook doesn't respect configuration files #155

asottile opened this issue Apr 3, 2021 · 21 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @pbaranay on Sep 13, 2016, 12:58

My project has a couple settings defined in our .flake8 file, such as:

[flake8]
max-line-length = 120

When running flake8 directly the options are respected, as one expects. However, I recently used flake8 --install-hook=git to install the flake8 pre-commit hook. It seems that the flake8 application which is run via the hook does not pick up these settings:

$ git commit
/var/folders/wd/xwtcqngj7kz6sc8ff150dslr0000gn/T/tmp2l2N6g/[FILENAME_ELIDED].py:85:80: E501 line too long (82 > 79 characters)
[...]

I'm not sure if this is intended behavior or a bug. In either case, I'd appreciate some guidance on how to alter the hook to handle simple options.

Thanks for your help.

P.S. I tried duplicating my .flake8 file into the other possible configuration filenames (tox.ini and setup.cfg) and did not observe any change in behavior.

====

  • Python 2.7.10
  • Installed via pip 8.1.2
  • Setuptools version 24.0.3
  • Flake8 3.0.2 (mccabe: 0.5.1, pyflakes: 1.2.3, pycodestyle: 2.0.0) CPython 2.7.10 on Darwin`
@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @wjanssen on Sep 27, 2016, 10:26

I'm seeing this as well.

Linux 16.04, Python 2.7.12, Flake8 2.5.4 (pep8: 1.7.0, mccabe: 0.5.2, pyflakes: 1.1.0) CPython 2.7.12 on Linux

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @wjanssen on Sep 27, 2016, 10:27

Running flake8 on the command-line also seems to ignore setup.cfg and .flake8.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @wjanssen on Sep 27, 2016, 10:30

This is almost certainly issue #210

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @Stavros on Sep 29, 2016, 15:50

@wjanssen I doubt that, my setup.cfg is committed and yet I still get errors when committing.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @phdru on Sep 30, 2016, 08:32

My setup.cfg is committed and flake8 still ignores it. I'm sure it's a bug.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sergioalonso on Oct 30, 2016, 15:45

Mentioned in merge request !131

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 8, 2016, 19:13

Mentioned in merge request !136

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 8, 2016, 19:14

Could y'all test the wheel generated by the CI in !136. I believe this will fix the issue y'all found here.

Thanks again for reporting this!

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @Stavros on Nov 9, 2016, 08:09

!136 works in that it respects the configuration file. It fails in that it still allows the commit to happen, even though there are errors. Is there a ticket related to that that I can comment on?

This ticket can probably be resolved, if the other testers' results are similar to mine.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @phdru on Nov 9, 2016, 08:19

Currently I cannot reproduce the problem with flake8 3.0.4.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 9, 2016, 08:23

@Stavros, we lost our documentation for configuring the git hook to prevent commits, try configuring "flake8.strict" to be true via git-config. We will read flake8 config values from your project's git configuration.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @Stavros on Nov 9, 2016, 08:26

@sigmavirus24 That worked, thank you. What do you mean by "lost the documentation", though? Did the documentation mention a way to do this when adding the hook, or...?

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 9, 2016, 08:33

See #249, @Stavros. The 2.x version of Flake8's docs mentioned using git config and hg config for this if I remember correctly. I forgot to keep that documentation when I rewrote the docs from scratch for 3.x.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @Stavros on Nov 9, 2016, 08:37

Ah, I see, thanks. Would it not be less surprising to have the strict behaviour on by default? My reasoning is that, if I care enough to add a hook, I care enough to fix the errors. I can issue a MR if you agree.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 9, 2016, 09:56

@Stavros I do not agree, mainly since the time for backwards incompatible changes was when 3.0 was released. Not months later.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 9, 2016, 10:02

Status changed to closed by commit 7320cce

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 9, 2016, 15:09

Mentioned in commit sigmavirus24/flake8@5b1d84f

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 13, 2016, 12:51

Mentioned in merge request !147

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 13, 2016, 12:59

Mentioned in commit 7800351

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @cmdelatorre on Jan 28, 2018, 16:39

Hi there, just checking: this issue wasn't fixed, right?
I think I'm running into this.

$ python --version
Python 3.5.2  
$ flake8 --version  
3.5.0 (mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 3.5.2 on Linux

In any case, I solved it by replacing the hook that flake8 creates with a somewhat simpler one (which respects my custom settings):

#!/bin/sh
flake8

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @roganov on Mar 13, 2018, 02:18

Does not work for me as well. Can this be reopened please?

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