evolution
evolution

Reputation: 4742

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)

Upvotes: 30

Views: 29052

Answers (6)

Volkov Maxim
Volkov Maxim

Reputation: 331

On Ubuntu 22.04 I had create file .flake8 in a root directory of a project and it works correctly.

Upvotes: 0

Matthijs Kooijman
Matthijs Kooijman

Reputation: 2797

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 (up to flake8 5.0), 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). Also note that this no longer works in flake8 5.0.0, since that explicitly ignores ~/.flake8:

Fix ignoring of configuration files exactly in the home directory (See also #1617, #1618).

Upvotes: 24

Jabba
Jabba

Reputation: 20664

If you want to use Flake8 with VS Code, then do the following:

  • Install the VS Code extension called flake8
  • Read the documentation of the extension! It tells you to use the setting flake8.args
  • Add your settings to settings.json. Example:
"flake8.args": [
    "--max-line-length=100",
    "--ignore=E501,W503,W504,E203",
    "--max-complexity=10",
  ],

Upvotes: 7

eric
eric

Reputation: 8098

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.

Upvotes: 11

CharlesG
CharlesG

Reputation: 357

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.

Upvotes: 3

Ian Lee
Ian Lee

Reputation: 502

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

Upvotes: 2

Related Questions