demand
When reading some source code, I want to take a look at its UML class diagram.
The search found that the existing software can achieve this function.
install software
Personal development environment: windows + vscode
- Graphviz
can be installed on the official website: graphviz
Note: After installation, add the installation path to the environment variables. My path isC:\Program Files (x86)\Graphviz2.38\bin
- pyreverse
This program has been integrated in the pylint module. If pylint is not installed, you need to install it first:pip install pylint
use
Operating procedures:
- Want to perform class analysis on test.py
- Open the cmd or powershell window under the script folder. After executing the following command, classes.png will be generated in the current folder.
pyreverse -ASmy -o png test.py
You can also specify the output file name:,pyreverse -ASmy -o dot -p test test.py
and classes_test.png will be generated after running.
Note: I could not directly generate this command in one step, so it can be divided into two steps.
pyreverse -ASmy -o dot test.py
Execute this command on the command line (python), the role: pyreverse will analyze the class relationship in test.py, and then generate the classes.dot file.
The output file name can be specified:,pyreverse -ASmy -o dot -p test test.py
and the classes_test.dot file will be generated after running.
You can also specify a folder analysis:pyreverse -ASmy -o dot folder/
Note: see other blog can generate images directly step:pyreverse -ASmy -o png test.py
. But I will report an error, see the prompt message: only support dot file output. Then turn around again.dot -Tpng classes.dot -o test.png
Executing this command on the command line has the effect: graphviz parses the .dot file into a picture.
The result diagram is as follows:
Only the inheritance relationship can be seen (simple conjecture: if you want to analyze other types of relationships, such as dependencies, combinations, etc., it will greatly increase the complexity.) Anyway, temporarily meet the simple needs. I want to look at other relationships in the future, and then study it carefully.