How to enable automatic code formatting for flake8 in PyCharm

I use Tox to run unit tests with the flake8 command, which checks for code formatting errors. Every time I code in PyCharm, I run tox, and then I realize that I have a bunch of annoying formatting errors that I have to return and fix manually. I would like PyCharm to automatically format the code (according to flake8 google for me every time it is automatically saved after I stopped typing.

My Testenv toxins are as follows:

[testenv:flake8] commands=flake8 <my_code_directory> deps = flake8==2.4.1 flake8-import-order==0.11 pep8-naming==0.4.1 [flake8] max-line-length = 120 import-order-style = google 

Is it possible? Do I need to download a specific plugin somewhere? If not with flake8, but what about PEP-8?

+12
source share
2 answers

Flake8 and the import order cannot be automatically corrected to match what you see. You can automatically fix pep8 with autopep8.

There is discussion here about implementing this for Flake8.

+7
source

To automatically sort import statements, use isort . Try using black to automatically format Python code.

+4
source

Source: https://habr.com/ru/post/1014498/


All Articles