3

I'm trying to change the line length for flake8 (version 3.7.7) on OSX (10.14.5), so that it matches the line length used in Black (the Python auto formatter). I'm using Sublimetext 3 with the SublimeLinter-flake8 plugin.

What I've tried to do is create a folder ~/.config/flake8 and then placed a file in it with the settings:

[flake8]
max-line-length = 88

I have called this file config.flake8. In addition, I've tried naming it 'flake8', 'flake8.rc', placing it in both ~/.config and ~/.config/flake8.

However, this hasn't worked. I get

./lorenz.py:13:80: E501 line too long (81 > 79 characters)

both when I run flake8 in the terminal (so this is not an ST3 problem) and when I have the code open on Sublimetext3.

I've looked at the documentation for flake8 and haven't really been able to get much out of it.

Can anyone let me know where I'm going wrong?

J. Jaksche
  • 131
  • 9

2 Answers2

1

Instead of putting a file into the directory ~/.config/flake8, the name of the file should be flake8 and it should be placed in the ~/.config directory:

For example with the config in the following location:

$ cat ~/.config/flake8 
[flake8]
max-line-length = 88

I can now see that flake8 gives warnings about 88 line length lines:

$ python3 -m flake8 
./pinpoint-poc-db-listener.py:17:89: E501 line too long (96 > 88 characters)
./pinpoint-poc-db-listener.py:18:89: E501 line too long (248 > 88 characters)

Reference: https://flake8.pycqa.org/en/latest/user/configuration.html

JD D
  • 7,398
  • 2
  • 34
  • 53
  • I don't think that makes much sense. Maybe you understood it wrong? – Luca Bezerra Jun 09 '19 at 13:15
  • What I mean is that you can't have forward slashes in a filename: https://stackoverflow.com/questions/9847288/is-it-possible-to-use-in-a-filename. Your `cat` command is reading from a file in a path. – Luca Bezerra Jun 09 '19 at 13:32
  • Thankyou for the quick reply. I've renamed the file ~/.config/flake8, and placed it in ~/.config. However, I'm still getting `./lorenz.py:13:80: E501 line too long (81 > 79 characters)`. – J. Jaksche Jun 09 '19 at 13:32
  • the file should be named `flake8` and placed in the `~/.config` folder – JD D Jun 09 '19 at 13:34
  • 1
    @JDD You do realize that's not what you said in the first line of your answer, right? – Luca Bezerra Jun 09 '19 at 13:35
  • Sorry for the confusion, I have updated the wording to be more clear. I tried to give the CLI example to make it more clear what I was trying to convey. – JD D Jun 09 '19 at 13:36
  • 1
    Thanks, this worked. I had (well, thought I had) already tried just calling the file `flake8` and found it didn't work, but I didn't realise that it was actually hiding the extension and instead was called `flake8.flake8`... There's a small typo in your answer, I believe the first instance of `flake` should be `flake8`. – J. Jaksche Jun 09 '19 at 14:33
  • @J.Ligeti thanks, I fixed the typo to correct it to say `flake8` sorry for all of the edits to make this clear – JD D Jun 09 '19 at 14:44
  • `flake8` 4 no longer supports `.config/flake8` https://stackoverflow.com/a/71974264/1671227 – A G Jun 29 '22 at 09:48
0

Does it have to be a system-wide configuration, or could it be just for that one project? If the latter applies, you could try saving it to a file called .flake8 in your project's root folder.

Luca Bezerra
  • 1,160
  • 1
  • 12
  • 23