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?
Add a file .flake8
with the following :
[flake8]
max-line-length = 120
You can also do the same using a setup.cfg
file.
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.
flake8 doesnt natively support pyproject.toml
file yet. You can install Flake8-pyproject to add this functionality.
pip install Flake8-pyproject
Then you can simply use the `pyproject.toml to change flake8 settings like below:
[tool.flake8]
max-line-length = 120
I think it good idea with
[tool.flake8]
max-line-length = 88
Modern Python projects that use pyproject.toml
can do the following:
# We hate arbitrary line lengths
[tool.black]
line-length = 999
No additional files needed.
pyproject.toml
should be the default for all Poetry-based projects.
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.
flake8
won't look into your pyproject.toml
file. Put it into .flake8
instead. –
Frontage setup.cfg
–
Tko © 2022 - 2024 — McMap. All rights reserved.