Log Management and Analytics

Explore the full capabilities of Log Management and Analytics powered by SolarWinds Loggly

View Product Info

FEATURES

Infrastructure Monitoring Powered by SolarWinds AppOptics

Instant visibility into servers, virtual hosts, and containerized environments

View Infrastructure Monitoring Info

Application Performance Monitoring Powered by SolarWinds AppOptics

Comprehensive, full-stack visibility, and troubleshooting

View Application Performance Monitoring Info

Digital Experience Monitoring Powered by SolarWinds Pingdom

Make your websites faster and more reliable with easy-to-use web performance and digital experience monitoring

View Digital Experience Monitoring Info

Blog Python

Automating Pylint Integration With Jenkins

By Hoover J. Beaver 01 Sep 2011

If you write a lot of Python code it pays to setup ways to automate code quality control. Jenkins, an open source continuous integration server, is a great platform for: automated testing, code coverage reports, and static analysis with Pylint. In this blog post, I am only going to focus on Pylint, but stay tuned for more Jenkins topics in the future.

Pylint, if you haven’t used it before, is the defacto static analysis tool for Python programmers. It isn’t perfect, and it does need a decent amount of configuration and tuning, but it is quite useful. At Loggly we are using Jenkins to automatically run Pylint on git pushes to Master. You can see a gist of our Pylint command here: https://gist.github.com/1175983.

One strategy to get Pylint integrated into an automated build of your software is to set a low bar. More then likely you will need to turn off many warnings, initially, to get things working on every checkin. Once you have this automated, you can then get fancier and slowly turn up the “heat” on your code. If you look at the pylint command above, you will notice that the following warnings were turned off: W0622,W0611,F0401,R0914,W0221,W0222,W0142,F0010,W0703,R0911.For example, one of the disabled warnings above is: R0911: Too many return statements (%s/%s) Used when a function or method has too many return statement, making it hard to follow. Once things are stabilized for a few days under the current Pylint settings, we may look to refactor the code to eliminate some of these return statements and turn the warning back on.

Jenkins has an interesting plugin called Violations, which can reject a build, based on a Pylint score threshold. If you look at the following Pylint output, you will see a Pylint score of 10/10: https://gist.github.com/1176006. If the Pylint score dropped below 10 on a git push, a build failure would occur as shown in picture below.

I hope you enjoyed the blog post, and if you have a Jenkins/Pylint, we would love to hear from you.

References

1. Writing clean, testable, high quality code in Python: https://www.ibm.com/developerworks/aix/library/au-cleancode/

2. Jenkins CI: https://jenkins-ci.org/

3. Pylint: https://www.logilab.org/857

The Loggly and SolarWinds trademarks, service marks, and logos are the exclusive property of SolarWinds Worldwide, LLC or its affiliates. All other trademarks are the property of their respective owners.
Hoover J. Beaver

Hoover J. Beaver