Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting Pylint Score

Tags:

python

pylint

Does anyone know how to extract only the pylint score for a repository?

So, assuming pylint produces the following output:

Global evaluation
-----------------
Your code has been rated at 6.67/10 (previous run: 6.67/10, +0.00)

I would like it to return a value of 6.67.

Thanks,

Seán

like image 398
Seán Avatar asked Sep 12 '16 15:09

Seán


People also ask

How do I find my pylint score in VS code?

pylintrc and put it in the master folder; running Pylint from the command line displays the score.

What is acceptable pylint score?

Pylint. Run pylint on your code before checking in. New files shall have a Pylint score of 9 or higher. New files will not be accepted if they have a Pylint score lower than 9.

How do you read pylint output?

Output optionsThe simplest way to output to a file is with the --output=<filename> option. The default format for the output is raw text. You can change this by passing pylint the --output-format=<value> option. Possible values are: text , json , parseable , colorized and msvs (for Visual Studio).


2 Answers

If you just want the score, why not grep do the heavy work?

(py3_venv) pylint script.py | grep rated
Your code has been rated at 2.65/10 (previous run: 7.65/10, +0.00)
like image 195
Ravi Kumar Avatar answered Oct 23 '22 23:10

Ravi Kumar


You can run pylint programmatically and get to the stats dictionary of the underlying "linter":

from pylint.lint import Run

results = Run(['test.py'], do_exit=False)
# `exit` is deprecated, use `do_exit` instead
print(results.linter.stats['global_note'])
like image 43
alecxe Avatar answered Oct 23 '22 21:10

alecxe