flake8 is not picking up global configuration file in user directory
Asked Answered
S

2

5

I have flake8 installed in pipenv virtual environments on per project basis.

The flake8 docs state that:

Values set at the command line have highest priority, then those in the project configuration file, then those in your user directory, and finally there are the defaults.

As per the docs I created two .flake8 files:

  1. In the project root - for per project configuration
  2. /Users/rusl/.config/flake8/.flake8 - for global configuration

When I run flake8 it picks up configuration options from a local file, but it completely ignores the global file.

How can I make flake8 see the global configuration file so I don't have to repeat some configuration options in every project?

Satinwood answered 20/2, 2021 at 17:14 Comment(1)
The global configuration is ~/.config/flake8. That's a file, not a directory.Zaragoza
N
5

This answer is for flake8 < 4.0.0.
For flake8 4.0.0 and up, see farnsy's answer.


It can be a bit misleading, but the User Configuration section of the flake8 docs does mention a file:

Flake8 allows a user to use “global” configuration file to store preferences.

...

Note that Flake8 looks for ~\.flake8 on Windows and ~/.config/flake8 on Linux and other Unix systems.

As answered in the comments, ~/.config/flake8 should be a file, not a directory.

Nickerson answered 20/2, 2021 at 17:14 Comment(2)
It definitely mislead me! )) although the absence of the slash should have given me a hint!Satinwood
Please see @farnsy's answer, and update this answer accordingly. Flake8 no longer loads a global configuration file. The section is removed from the documentation as well.Spectroheliograph
L
18

Note that as of flake8 4.0, flake8 no longer supports a global config file at all. I don't know what could motivate such a horrible idea, but that's where we are.

Lots of docs are not up to date on this, so maybe this answer will help guide some people who think flake8 is ignoring their global config due to user error. It's not you, it's them.

Laminate answered 5/9, 2022 at 3:2 Comment(2)
A terrible decision, I've spent already an hour today on broken tools so far =\Olander
Time to switch to Ruff I guess, I've only heard good things about itSatinwood
N
5

This answer is for flake8 < 4.0.0.
For flake8 4.0.0 and up, see farnsy's answer.


It can be a bit misleading, but the User Configuration section of the flake8 docs does mention a file:

Flake8 allows a user to use “global” configuration file to store preferences.

...

Note that Flake8 looks for ~\.flake8 on Windows and ~/.config/flake8 on Linux and other Unix systems.

As answered in the comments, ~/.config/flake8 should be a file, not a directory.

Nickerson answered 20/2, 2021 at 17:14 Comment(2)
It definitely mislead me! )) although the absence of the slash should have given me a hint!Satinwood
Please see @farnsy's answer, and update this answer accordingly. Flake8 no longer loads a global configuration file. The section is removed from the documentation as well.Spectroheliograph

© 2022 - 2024 — McMap. All rights reserved.