Pyreverse analyses Python code and extracts UML class diagrams and package depenndencies. Since september 2008 it has been integrated with Pylint (0.15).
Introduction
- Pyreverse builds a diagram representation of the source code with:
- class attributes, if possible with their type
- class methods
- inheritance links between classes
- association links between classes
- representation of Exceptions and Interfaces
Generation of UML diagrams with Pyreverse
The command pyreverse generates the diagrams in all formats that graphviz/dot knows, or in VCG :
The following command shows what dot knows:
$ dot -Txxx Format: "xxx" not recognized. Use one of: canon cmap cmapx cmapx_np dia dot eps fig gd gd2 gif hpgl imap imap_np ismap jpe jpeg jpg mif mp pcl pdf pic plain plain-ext png ps ps2 svg svgz tk vml vmlz vrml vtx wbmp xdot xlib
pyreverse creates by default two diagrams:
$ pyreverse -o png -p Pyreverse pylint/pyreverse/ [...] creating diagram packages_Pyreverse.png creating diagram classes_Pyreverse.png
- -o : sets the output format
- -p name : yields the output files packages_name.png and classes_name.png
Options
One can modify the output with following options:
-a N, -A depth of research for ancestors -s N, -S depth of research for associated classes -A, -S all ancestors, resp. all associated -m[yn] add or remove the module name -f MOD filter the attributes : PUB_ONLY/SPECIAL/OTHER/ALL -k show only the classes (no attributes and methods) -b show 'builtin' objects
Examples:
General Vue on a Module
pyreverse -ASmy -k -o png pyreverse/main.py -p Main
With these options you can have a quick vue of the dependencies without
being lost in endless lists of methods and attributes.
Detailed Vue on a Module
pyreverse -c PyreverseCommand -a1 -s1 -f ALL -o png pyreverse/main.py
Show all methods and attributes of the class (-f ALL).
By default, the class diagram option -c uses the options
-A, -S, -my, but here we desactivate them
to get a reasonably small image.
Configuration File
You can put some options into the file ".pyreverserc" in your home directory.
Exemple:
--filter-mode=PUB_ONLY --ignore doc --ignore test
This will exclude documentation and test files in the doc and test
directories. Also, we will see only "public" methods.
blog entry of
![[image : classes_Pyreverse.png]](./css/classes_Pyreverse.png)
Comments
In this post they show how to have a beautifull svg (one dot/graphviz output) with shades using xsl.
The second sentence in the first paragraph says that it's already integrated with Pylint >0.15 .
So the download link could be: ./diagrams/project/pylint
However you can do it with 'easy_install pylint' if you have setuptools installed, link: http://lmgtfy.com/?q=setuptools
easy_install has the advantage of taking care of the package dependencies for you which is great help.
For easy_install to work on windows, you need to set your path manually to include c:\python\scripts (substitute c:\python with your python installation path).
pyreverse needs graphviz/dot what you can get at: http://www.graphviz.org/Download..php (for real)
On windows, you may need to adjust the path for this too, but in many cases only a restart after installation will do. Other times do a search for dot.exe and add the directory containing it to your path.
I hope I made this article more useful for those who found it useless previously.
Great scripts been playing around today, one question has anyone got a config.bat file example so I do not need to call pyreverse by command line?? Probably simple to those in the know! Thanks, Alan
images on this page are not found - can be be made available again?