Pyreverse
From charlesreid1
Pyreverse is a tool in the Pylint tool suite. Pyreverse is a tool for generating UML diagrams from Python source code.
Contents
Examples
Olipy
Here's a UML diagram of the Olipy library. I generated this using the pyreverse utility (part of the Pylint library).
$ pip install pylint $ cd /path/to/olipy $ pyreverse -o png -p OLIPY .
This generates the images classes_OLIPY.png
and packages_OLIPY.png
:
Scipy
$ pip install pylint $ git clone git@github.com:scipy/scipy.git $ cd scipy/ $ pyreverse -o png -p SCIPY .
This will dump out images called classes_SCIPY.png
and packages_SCIPY.png
.
Where Do I Run It
One of the confusing things about pyreverse is that it won't give particularly sensible output if you just run pyreverse on the top level package. To use pyreverse effectively, do the following:
- If the top level package has no submodules, just run pyreverse on the top level package (run the pyreverse command in the directory containing hte python module)
- If the top level package has multiple submodules, cd into the submodule folder of interest. You can run pyreverse from this submodule folder to create a UML diagram incorporating all classes from that submodule
- Limit the scope of what pyreverse is looking at as much as possible - if a submodule has multiple sub-directories, you can cd into the sub-directory and run pyreverse from there to further limit the classes you're incorporating into the UML
Customizing Output
Some tips + usage here: https://gist.github.com/HarshaVardhanBabu/9a47db9e33cf06e9e1e917520bb54056
Limiting included classes
use the -c CLASSNAME
or --class=CLASSNAME
flags to specify which classes to include in the diagram. Only those classes and related classes will be included.
Example
Suppose we have the following directory structure for a package called deepchem
:
$ tree deepchem/models/ deepchem/models/ ├── __init__.py ├── classes_DEEPCHEM.png ├── layers.py ├── models.py ├── multitask.py ├── packages_DEEPCHEM.png ├── sklearn_models │ └── __init__.py ├── tensorgraph │ ├── IRV.py │ ├── __init__.py │ ├── activations.py │ ├── fcnet.py │ ├── graph_layers.py │ ├── initializations.py │ ├── layers.py │ ├── model_ops.py │ ├── models │ │ ├── __init__.py │ │ ├── atomic_conv.py │ │ ├── gan.py │ │ ├── graph_models.py │ │ ├── ontology.py │ │ ├── resnet50.py │ │ ├── robust_multitask.py │ │ ├── scscore.py │ │ ├── seqtoseq.py │ │ ├── sequence_dnn.py │ │ ├── symmetry_function_regression.py │ │ ├── text_cnn.py │ │ └── unet.py │ ├── optimizers.py │ ├── progressive_multitask.py │ ├── regularizers.py │ ├── robust_multitask.py │ ├── sequential.py │ ├── symmetry_functions.py │ ├── tensor_graph.py │ └── tests │ ├── __init__.py │ ├── example_DTNN.mat │ ├── test_atomic_conv.py │ ├── test_estimators.py │ ├── test_gan.py │ ├── test_graph_models.py │ ├── test_layers.py │ ├── test_layers_eager.py │ ├── test_layers_pickle.py │ ├── test_model_ops.py │ ├── test_nbr_list.py │ ├── test_ontology.py │ ├── test_optimizers.py │ ├── test_resnet50.py │ ├── test_sascore.py │ ├── test_seqtoseq.py │ ├── test_sequencednn.py │ ├── test_sequential.py │ ├── test_symmetry_functions.py │ ├── test_tensor_graph.py │ ├── test_textcnnmodel.py │ └── test_unet.py ├── tests │ ├── __init__.py │ ├── butina_example.csv │ ├── example.csv │ ├── example_DTNN.mat │ ├── example_classification.csv │ ├── example_regression.csv │ ├── feat_multitask_example.csv │ ├── gaussian_cdf_example.csv │ ├── gbd3k.pkl.gz │ ├── multitask_example.csv │ ├── nnscore_example.pkl.gz │ ├── sparse_multitask_example.csv │ ├── test_api.py │ ├── test_generalize.py │ ├── test_multitask.py │ ├── test_overfit.py │ ├── test_predict.py │ ├── test_reload.py │ ├── test_singletask_to_multitask.py │ └── user_specified_example.csv └── xgboost_models └── __init__.py
Furthermore, suppose we want to print out the UML diagram for a particular class, like the Adam class, which extends the base Optimizer class to implement an Adam optimization method. This class is located in optimizers.py here:
deepchem/models/tensorgraph/optimizers.py
To run pyreverse and generate the UML diagram for the Adam optimizer class, cd into the models folder:
cd deepchem/models
Now you can specify one class (and all its related/parent classes) to include on the UML diagram using tensorgraph.optimizers.Adam
(which specifies a class Adam in the folder tensorgraph/optimizers/
:
$ pyreverse -o png -c tensorgraph.optimizers.Adam -k -s 0 -p DEEPCHEM .
Flags
Python a powerful programming language
Scientific Python: Data analysis libraries: Scipy · Numpy · Pandas · Statsmodel Machine learning libraries: Sklearn Neural network libraries: Tensorflow · Keras Plotting/viz: Matplotlib · Seaborn · Jupyter Solving partial differential equations and bessel functions: Fipy · Bessel Functions
Web and Networking Python: Web programming: Flask · Webapps · Mechanize · Scrapy · Gunicorn Wifi: Wireless/Python · Scapy IPython and Jupyter: Jupyter
Drawing, Geometry, and Shapes: Shapely (for drawing shapes): Shapely Geography library: Geos
General Useful Python Utilities: Python Remote Objects: Pyro Logging (create multi-channel log messages): Logging Keyboard (control keyboard from Python): Keyboard
Black Hat Python: Network scanning: Python/Scanner
|