Physics Derivation Graph navigation Sign in

cleaning up the code using pylint and flake8 and bandit

Published 2018-08-02T23:42:00.001Z by Physics Derivation Graph

I realized with so much Python, there's a need to clean up the code.
In this post I document a few software tools I used.


$ pylint --disable bad-whitespace,missing-docstring,superfluous-parens,bad-indentation,line-too-long,trailing-whitespace,len-as-condition,too-many-locals,invalid-name,too-many-branches,too-many-return-statements,too-many-statements --reports=n

and flake8

$ flake8 --ignore=E111,E225,E231,E501,E226,W291,E221,E115,E201,W293,E261,E302,E265

Not surprisingly, some of my functions are complicated (a score of greater than 10 is frowned upon)
$ python -m mccabe --min 9 | wc -l
$ python -m mccabe --min 15 | wc -l
So 15 functions scored 9 or greater; 4 functions were 15 or higher!

That's out of 50 functions and 1946 lines of Python (including comments and blank lines) $ cat | wc -l
$ cat | grep "^def " | wc -l

Although I'm not concerned about security of a locally run Python script, I also tried bandit:
$ bandit -r
which complained about my use of the shell.

I'm aware of autopep8 but haven't used it yet.