views:

2620

answers:

10

What tools are good to use for code analysis in python?

I have a large source repository split across multiple projects, and I would like to be able to run tools across the directories to see details like Cyclomatic Complexity, and perhaps be able to spot errors using static analysis.

Ideally, I would like to be able to produce a report about the health of the source code, so we can spot problem areas that need to be addressed.

+9  A: 

For static analysis there is pylint and pychecker. Personally I use pylint as it seems to be more comprehensive than pychecker.

For cyclomatic complexity you can try this perl program, or this article which introduces a python program to do the same

freespace
A: 

I have used pylint which does some higher analysis, but mostly its things like empty except blocks and the kind.

A quick googeling also found this, a perl program that analysis cyclomatic complexity of python programs. I'm sceptic...

Mr Shark
+2  A: 

Thanks to Pydev, you can integrate pylint in the Eclipse IDE really easily and get a code report each time you save a modified file.

Pierre-Jean Coudert
+1  A: 

Check out pyflakes from divmod.

Jeremy Cantrell
+7  A: 

For measuring cyclomatic complexity, there's a nice tool available at traceback.org. The page also gives a good overview of how to interpret the results.

+1 for pylint. It is great at verifying adherence to coding standards (be it PEP8 or your own organization's variant), which can in the end help to reduce cyclomatic complexity.

Mike Griffith
+1  A: 

There is a tool called CloneDigger that helps you find similar code snippets.

Anonymous
+1  A: 

Pymetrics

maplpro
+1  A: 

The SD Python CloneDR is a tool for finding exact and near-miss copies of cloned code across large Python systems.

By parsing Python according to its grammar, the CloneDR can use the code structure itself to help find clones in spite of different indentation, reformatting, addition/change of comments, renamed variables, and some statement insertions/deletions.

CloneDR also works for other langauges such as Java, C++, C#, ...

Sample clone detection reports can be found at the website.

Ira Baxter
+2  A: 

Pycana works like charm when you need to understand a new project!

PyCAna (Python Code Analyzer) is a fancy name for a simple code analyzer for python that creates a class diagram after executing your code.

See how it works: http://pycana.sourceforge.net/

output:

alt text

noinflection
+1  A: 

Pypants - PyPi package analyzer (uses pylint and pychecker)

sorki