The following is based on the answers to this StackOverflow question: Descriptive flake8 errors in PyCharm

At the time of writing (2019-05) PyCharm doesn’t have support for Flake8. There is a way to use it as an external tool.

First, make sure that flake8 is installed in the current environment. For a Windows venv project the path will be:

full_file_system_path\venv\Scripts\flake8.exe

Then, go to the PyCharm’s File menu and browse to File > Settings. In the “Settings” window, find Tools > External Tools and add a new external tool configuration.

For the program, use a macro that specifies the full file system path to the project directory:

$ProjectFileDir$\venv\Scripts\flake8.exe

The arguments line is:

$FilePath$ --format='%(path)s:%(row)d,%(col)d:%(code)s:%(text)s:https://lintlyci.github.io/Flake8Rules/rules/%(code)s.html'

The --format key will present the output in a descriptive way and provide a link to the error description located at the Flake8Rules project.

To test for McCabe complexity add the --max-complexity parameter. Its value should be around 10-12:

--max-complexity 12 $FileDir$ --format='%(path)s:%(row)d,%(col)d:%(code)s:%(text)s:https://lintlyci.github.io/Flake8Rules/rules/%(code)s.html' 

Demo

Create a file app.py with the following content:

def f(a = 10):
  return a*10

In the Project file list, right-click the file and select External Tools > flake8. You should see the output like this:

Categories: Python

2 Comments

Oleg · October 9, 2019 at 1:19 pm

test comment

Mar · November 24, 2020 at 11:49 pm

Thank you

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *