4

I have loaded black and flake8 into a poetry virtual environment. I'd like to change the default line length in black or flake8 so they agree. What is the best way to do this?

user12865812
  • 87
  • 1
  • 2
  • 6

3 Answers3

3

Add a file .flake8 with the following :

[flake8]
max-line-length = 120

You can also do the same using a setup.cfg file.

Thierry Nowak
  • 206
  • 2
  • 6
1

You can use pyproject-flake8 , a monkey patching wrapper to connect flake8 with pyproject.toml configuration.

or use FlakeHeaven : This project is a fork of FlakeHell.

FlakeHell and other forks of it such as flakehell/flakehell are no longer maintained and do not work with Flake8 4.0.x.

Flamingo
  • 322
  • 1
  • 11
-3

The short answer is add this to your pyproject.toml file (assuming you are using one since you are using poetry) and you should be good to go.

[flake8]
max-line-length = 88
extend-ignore = E203

This implies that the line length used by flake8 is set to 88, which is also the default used by black.

I would recommend that you take a look at the Line Length section of Black's README. The above snippet is taken from there. Black's authors also explain the rationale behind the choice of the default value. They also detail alternative options to make flake8 happy.

abn
  • 318
  • 2
  • 5