PyNSource
Home Up PyNSource Installation PyNSource Screenshots PyNSource Ascii UML PyNSource Java Code Generation PyNSource Mailing List

 

A UML reverse engineering tool for Python source code

A python code scanner and UML modelling tool that generates 

bulletUML diagram models that you can layout, arrange and print out.
bulletUML text diagrams, which you can paste into your source code for documentation purposes.
bulletJava or Delphi code (which can be subsequently imported into more sophisticated UML modelling tools, like Enterprise Architect or ESS-Model (free).)

Features

bulletResilient: doesn't import the python files, thus will never get "stuck" when syntax is wrong. 
bulletFast
bulletRecognises inheritance and composition  relationships
bulletDetects the cardinality of associations e.g. one to one or 1..*  etc
bulletOptionally treat modules as classes - creating a pseudo class for each module - module variables and functions are  treated as attributes and methods of a class
bulletHas been developed using unit tests (supplied) so that you can trust it just that little bit more ;-)
bulletFree
bulletThe significance of PyNSource (advocacy)...

Download and Installation

Screenshots

Ascii UML

Java Code Generation from python code

Join the mailing list and be notified when there are new releases of PyNSource.

GUI Usage

Run pynsourceGui.py e.g.

   C:\Python24\Lib\site-packages\pynsource\pyNsourceGui.py

or simply run the standalone pynsourceGui.exe.

Simply select from the menu "File Import..." and import the python modules you want to visualise.  Additional modules can be added to the diagram at any time.

You can drag around the classes to make your diagram look nice.  To get rid of the selection handles around a class, simply click on that class again with the mouse.

Command line Usage

 pynsource -v -m [-j | -d outdir] sourceDirOrListOfPythonFiles...   

  generate Ascii UML (i.e. don't specify any command line switches and it defaults to Ascii)
For more tips see Ascii UML
-j outdir generate .Java files, specify output folder for java files. See Java Code Generation from python code
-d outdir generate Delphi .pas files, specify output folder for delphi files. See Code Generation from python code
-v  verbose
-m  Optionally treat modules as classes - creating a pseudo class for each module - module variables and functions are  treated as attributes and methods of a class

Examples

e.g.

   \python22\python.exe  
      \Python22\Lib\site-packages\pynsource\pynsource.py 
      -d c:\delphiouputdir c:\pythoninputdir\*.py

The above line (please type all three lines  in on one single line) will scan all the files in c:\pythoninputdir and generate a bunch of delphi files in the folder c:\delphiouputdir

BASIC ASCII UML OUTPUT from PYTHON - EXAMPLES
e.g. pynsource Test/testmodule01.py
e.g. pynsource -m Test/testmodule03.py

GENERATE JAVA FILES from PYTHON - EXAMPLES
e.g. pynsource -j c:/try c:/try
e.g. pynsource -v -m -j c:/try c:/try
e.g. pynsource -v -m -j c:/try c:/try/s*.py
e.g. pynsource -j c:/try c:/try/s*.py Tests/u*.py
e.g. pynsource -v -m -j c:/try c:/try/s*.py Tests/u*.py c:\cc\Devel\Client\w*.py

GENERATE DELPHI  FILES from PYTHON - EXAMPLE
e.g. pynsource -d c:/delphiouputdir c:/pythoninputdir/*.py

See batch file usage for another handy way to drive pynsource from the command line.

 
TIP on long path names and path names with spaces: NOTE:  If you have long filenames, then enclosing paths and file references in double quotes is necessary and works ok. 
      e.g. "c:\Documents and Settings\Administrator\Desktop\stuff"

 

Future Directions & Help Needed

In priority order:

Need a smarter layout algorithm.  Please email me on suggestions on how to do this.   The quickest way is to borrow the layout algorithm inside Boa, though it probably won't handle the UML style layout of parent classes above and composed classes to the right.  Perhaps something good could be ported to python?

Allow the deletion of classes from diagrams.  This should be easy to do, and can relieve a lot of the clutter that can quickly build up in your diagrams. DONE - see release 1.4a. - right mouse click deletes classes.

Print needs to be smarter and allocate more than one page over which to spread the diagram.  Anyone who has used the wxPython printing component could help here.

Marquee selection facility - be able to select multiple uml classes at the same time, and be able to drag them around to position them.

Make the code parser smarter and smarter - not easy to do with a dynamic language like python.

Zoom out functionality - can use the approach used by UML Pad (which is written in wxWindows, though I think in C) which scales all objects on the canvas.  Works remarkably well.  We could port the algorithm over to wxPython and integrate it into PyNSource.  Or maybe ditch wx and use Java/Jython based swing GUI  with zoom+ graph layout?

Persistence - save diagrams to disk and then as you re-import only changes are updated.  That way a nicely laid out diagram could always be kept up to date.  Could save in standard UML xml format, which could then be imported into other uml modellers which can read xml.

Add all the features of the command line parser to the GUI.  E.g. The java and delphi code generation, the Ascii UML generation.  Perhaps even have 'batch jobs' that could be run periodically to regenerate any java or delphi source code, which is then in turn imported by a third party UML modeller.

If you like PyNSource then have a go at one of the tasks above, and send me the patches & I will incorporate and re-release.

Acknowledgements

Thanks to Denis Dube for the recursive import algorithm and some misc GUI fixes, including the initial version of the  print preview support.
Thanks to Vern Muhr for fixing a small bug in Printing.
Thanks to Thomas Margraf for working out the tweak to make the GUI run under wxpython 2.5 (even on a Mac!).

Send all comments to Andy Bulka.

Join the mailing list and be notified when there are new releases of PyNSource.