1

I want to calculate Cyclomatic Complexity by using PyLint. I need to have a python script that calculates the complexity of many modules at once.

I have tried using command as well as through python program.

This is the command i'm using:

pylint shortQuestion.py --load-plugins=pylint.extensions.mccabe

This is the code i'm using in python:

import pylint.lint

pylint_opts = ['basics.py','--load-plugins=pylint.extensions.mccabe','--rcfile=~/.pylintrc']

pylint.lint.Run(pylint_opts)

Here is the result i get from the command and code:

Using config file /var/root/.pylintrc
************* Module shortQuestion
W:  5, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  6, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  7, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  8, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:  1, 0: Module name "shortQuestion" doesn't conform to snake_case naming style (invalid-name)
C:  1, 0: Missing module docstring (missing-docstring)
C:  4, 0: Function name "isContained" doesn't conform to snake_case naming style (invalid-name)
C:  4, 0: Missing function docstring (missing-docstring)
R:  5, 1: Unnecessary "else" after "return" (no-else-return)
W:  4,16: Unused argument 'cls' (unused-argument)

----------------------------------------------------------------------
Your code has been rated at -15.00/10 (previous run: 10.00/10, -25.00)

is the -15.00/10 Cyclomatic Complexity here? If yes, how can i get the output in formatted way? Since i need to calculate this complexity for many python modules at once. If not, how can i calculate this?

1 Answers1

0

The score that you are seeing at the end of you output is your overall score of your code quality based on pylint. If you fix all these warnings, the score will go to 10 out of 10.

The message that you should be seeing in case your cyclomatic complexity is too high is this:

R:1: 'function1' is too complex. The McCabe rating is 11 (too-complex)

See also the docs.