I'd like to extract my pylint rating and set a threshold. Let me explain, for example, if the score is under 5, I want exit 1; And if my code is rated higher than 5, I want exit 0 and continue my Jenkins procedure.
The score is calculated using Pylint version 2.4. 3 To calculate the coding convention score, we will use the standard coding convention score calculated by Pylint. The formula for this score is as follows: 10.0 - ((float(5 * Frequency of convention errors) / Number of statement) * 10).
In python, the most consensual writing style is defined by the PEP-8 standard, which the popular pylint package enforces. It comes with a handy metric, the Pylint score: you get a 10/10 for perfectly conforming to the standard, less it you stray from it.
Pylint is a Python tool that checks a module for coding standards. According to the TurboGears project coding guidelines, PEP8 is the standard and pylint is a good mechanical test to help us in attaining that goal.
Since pylint 2.5.0 there is a new argument called --fail-under
that resolves this question without needing external tools or scripts.
In this example, pylint will exit with error when score is under 8:
pylint --fail-under=8 python_code.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With