Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flake8 max-complexity per file

I have a legacy project using flake8 to check code quality and complexity, but the project has some very complicated (terrible) services which are returning complexity WARNING messages:

./service1.py:127:1: C901 'some_method' is too complex (50)

We are slowly transitioning into making them better, but we need to make jenkins (which is running tests and flake8) pass.

Is there a way to specify ignoring a code error or complexity per file, or even per method?

like image 728
eLRuLL Avatar asked Sep 07 '25 01:09

eLRuLL


2 Answers

If you have Flake8 3.7.0+, you can use the --per-file-ignores option to ignore the warning for a specific file:

flake8 --per-file-ignores='service1.py:C901'

This can also be specified in a config file:

[flake8]
per-file-ignores =
    service1.py: C901
like image 122
Eugene Yarmash Avatar answered Sep 09 '25 04:09

Eugene Yarmash


You can use flake8-per-file-ignores:

pip install flake8-per-file-ignores

And then in your config file:

[flake8]
per-file-ignores =
    your/legacy/path/*.py: C901,E402

If you want a per-method/function solution you can use the in-source # noqa: ignore=C901 syntax.

like image 36
Peque Avatar answered Sep 09 '25 05:09

Peque