'flake8 not picking up config file

I have my flake8 config file in ~/.config/flake8

[flake8]
max-line-length = 100

However when I run flake8 the config file is not picked up. I know that because i still get warnings over lines longer than 79 char.

I'm on redhat, but the same happens on mac.

I use pyenv. Global is 2.7.6 (not even sure this is relevant)



Solution 1:[1]

Sharing my mistake in case this can help someone:

I had a similar issue which was simply due to a bad file name: .flake8.txt instead of .flake8.

Correcting resolves the issue.

Solution 2:[2]

I had a silly mistake, leaving out the [flake8] tag at the beginning of my configuration file I just spent 2 hours debugging this problem.

Here was my original .flake8 file:

ignore=
    # line too long
    E501,
    #line break after binary operator
    W504

This was the fix:

[flake8]
ignore=
    # line too long
    E501,
    #line break after binary operator
    W504

Obviously this wasn't OP's problem: they have the tag in there. But if I can save one person from my stupidity, I will be happy. Frankly I was almost too embarrassed to post this because it is an "Is your computer plugged in?" level error, but oh well.

Solution 3:[3]

For anyone running into this more recently: I turns out flake8 4.x no longer supports loading .config/flake8, and seems to have no alternative.

From https://flake8.pycqa.org/en/latest/internal/option_handling.html#configuration-file-management :

In 4.0.0 we have once again changed how this works and we removed support for user-level config files.

As a workaround, you could try passing --append-config ~/.config/flake8 (possibly in a bash alias).

Alternatively, for code that lives in your homedir, you could create a ~/.flake8 config file, that will be picked up for any project inside your homedir that does not have its own flake8 config. This works because flake8 looks in the current directory (or maybe the directory with the source file) and then looks upwards through the filesystem until it finds a config file (setup.cfg, tox.ini, or .flake8). Note that documentation is a bit vague about this (suggesting it would not stop at the first config file it finds, but at least flake8 4.0.1 behaves like that).

Solution 4:[4]

This was caused by a regression in pep8 1.6.1 and is resolved in the just released 1.6.2 version.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CharlesG
Solution 2 eric
Solution 3 Matthijs Kooijman
Solution 4 Ian Lee