[ANN] PyStructure: Structure and Dependency Analyser for Python Projects

Robin Stocker robin at nibor.org
Mon Apr 14 11:27:17 EDT 2008


Hi Python developers,

We are happy to announce our first release of PyStructure, a structure 
and dependency analyser for Python code (written in Java). It is now in 
a state where it can parse and analyse real-world projects (with 
limitations, see below) and show the results in Structure101g, a 
dependency visualiser.

To try it out with your projects, download pystructure.zip from the 
following address and follow the instructions in the README file:

   http://pystructure.ifs.hsr.ch/release/

We are two students working on this as our bachelor thesis. The project 
page can be found at:

   http://pystructure.ifs.hsr.ch/

We are very eager to hear your feedback about our project. What do you 
think about the idea of a 'structural analyser' for a dynamic language 
like Python? Does it work for your project (probably not very well at 
the moment)?

Cheers,
   Reto Schüttel
   Robin Stocker


About PyStructure
-----------------

Our project's goal is to develop a structural analyser for programs 
written in the Python programming language. The analyser should be able 
to parse an application's source code, analyse it and then generate a 
graph representing the internal structure of the project.

As Python is a dynamic language most of the interesting details (i.e. 
type) are not known before the application is running. The analyser has 
to 'guess' the correct type by analysing the code base.

The project is licensed under the LGPL (v2 or later), see the COPYING file.


Current Limitations
-------------------

Although the engine already supports a wide variety of cases it still 
lacks some very important features:

  - No support for inheritance

    Currently the engine ignores everything that involves inheritance.
    For example if a method is implemented in a base class it won't be
    found if it was called on an instance of a sub class.

  - Type of list/dict elements is not known

    The type of container elements cannot be determined yet. For projects
    which heavily rely on lists this means that a lot of types can't be
    determined.

  - Only little support for built-ins

    Only a few built-in operations are recognised. For example the type
    inference engine doesn't yet know that len("str") returns an integer.

We are working on tackling these issues in the next two milestones and 
we hope to improve the accuracy of the engine significantly.


Possible Applications
---------------------

Our library (especially the type inferencer we use) might be interesting 
for other applications. For example:

  - Code completion and navigation in IDEs

And it might improve the accuracy of tools which:

  - Detect unused/dead code
  - Look for possible bugs in code (like FindBugs for Java)
  - Do type checks and optimisations at compile time


References
----------

  - DDP: Demand-Driven Analysis with Goal Pruning by Lex Spoon
     http://www.lexspoon.org/ti/

  - Headway Software
     http://www.headwaysoftware.com/





More information about the Python-list mailing list