Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class diagram viewer application for python3 source

Is there any application which can generate from python3 source something like the below link (i don't care about the representation rather the perfect content)

http://www.codeproject.com/KB/IP/Searcharoo_3/ClassDiagram.png

like image 809
vpas Avatar asked Apr 05 '16 16:04

vpas


2 Answers

Yes there is: with pylint comes pyreverse that will generate class diagrams (not as pretty as the one in reference I am afraid, but clear and useful.) There is a dependency with graphviz.

From command line:

To analyse a full or part of a package

$ pyreverse -o png -p <project name>

To analyse one specific file:

$ pyreverse -o png -p myproject \path\to\myproject\myfile.py 

Example output: Class Diagram

enter image description here

Example output: Packages

enter image description here

like image 69
Reblochon Masque Avatar answered Oct 18 '22 23:10

Reblochon Masque


I found that the accepted answer violated the principle of least surprise :)

Given a current directory that contains python files as well as source in subdirectories, running pyreverse -o png -p py_test . meant Pylint picked up __init__.py and then went on to create a UML diagram of r:\apps\python3\lib\encodings\.

Using pyreverse -o png -p py_test ./main.py generated a blank PNG as no classes where defined within that source file.

However, pyreverse -o png -p py_subdir ./py_subdir did get some sensible results. It generated both class and package diagrams for all code in the subdirectory. Somewhat counter-intuitive.

like image 21
J Evans Avatar answered Oct 19 '22 00:10

J Evans