Python code metrics

Recently at work I’ve been pushing to start tracking some metrics on our python code base. There are a few tools out there like pygenie, pychecker and pylint. These seem to be the leading code metric tools for python at the moment. Where I work we have eagerly adopted pylint in our daily use of python.

Pylint seems to be the most useful for the day to day developer. It’s fast and flexible, you can run it on the file you’re working in,a group of files or the entire project.

There are some problems with all of these tools when it comes to frameworks. I’ve been using django alot lately and with the way that it has it’s settings.py file integrated it kind of  tricks these lint tools. So you may see errors saying something like this…

ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

There are a couple django-lint checkers it appears.

django-lint is a project that appears to have died. I’ve tried to use this a little bit, but I haven’t really had much success.

It appears however that the project has moved or branched http://chris-lamb.co.uk/projects/django-lint.

I haven’t tried this version but I imagine it would be better since it was last updated in March 2010.

You can also set the DJANGO_SETTINGS_MODULE environment variable like this…

$ export DJANGO_SETTINGS_MODULE=mysite.settings
$ django-admin.py runserver

So here’s my story:

I have some surprising elements that came out of looking for lint tools for python or any other programming language that you’re working in.

One, was that my team latched on to the pylint scoring mechanism instantly and it became a game of who could get a perfect score over all the code they were working in.  This is good for a few reasons, and I challenge those nay sayers out there.

Warning: POINT ahead!

Ok yes, maybe “your” coding style isn’t accomodated in pylint…you know what! It doesn’t matter.  The POINT is that everyone is meeting a STANDARD.

That’s the point! I don’t care if no one can get a perfect score unless all their variables start with “i” (which I assume is Apple’s policy).  The power that comes with everyone driving, pushing and accelerating in the same direction is far far far more valuable than “your” coding style.

  • http://www.pointlessrants.com Eric Shull

    Interesting. I’ll have to play around with this.

    I liked your assumption about Apple’s policy. I wouldn’t be the least bit surprised if you were right.