Skip to content

Commit 614f80e

Browse files
Improve pyreverse documentation (#10063)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
1 parent a18a27f commit 614f80e

File tree

5 files changed

+146
-90
lines changed

5 files changed

+146
-90
lines changed

doc/additional_tools/pyreverse/configuration.rst

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,53 @@
22
.. docs extension in 'doc/exts/pyreverse_configuration.py'.
33
44
5+
Usage
6+
#####
57

6-
Pyreverse Configuration
7-
^^^^^^^^^^^^^^^^^^^^^^^
88

9+
``pyreverse`` is run from the command line using the following syntax::
10+
11+
pyreverse [options] <packages>
12+
13+
where ``<packages>`` is one or more Python packages or modules to analyze.
14+
15+
The available options are organized into the following categories:
16+
17+
* :ref:`filtering-and-scope` - Control which classes and relationships appear in your diagrams
18+
* :ref:`display-options` - Customize the visual appearance including colors and labels
19+
* :ref:`output-control` - Select output formats and set the destination directory
20+
* :ref:`project-configuration` - Define project settings like source roots and ignored files
21+
22+
23+
.. _filtering-and-scope:
924

1025
Filtering and Scope
11-
-------------------
26+
===================
27+
1228

1329
--all-ancestors
14-
"""""""""""""""
30+
---------------
1531
*Show all ancestors of all classes in <projects>.*
1632

1733
**Default:** ``None``
1834

1935

2036
--all-associated
21-
""""""""""""""""
37+
----------------
2238
*Show all classes associated with the target classes, including indirect associations.*
2339

2440
**Default:** ``None``
2541

2642

2743
--class
28-
"""""""
44+
-------
2945
*Create a class diagram with all classes related to <class>; this uses by default the options -ASmy*
3046

3147
**Default:** ``None``
3248

3349

3450
--filter-mode
35-
"""""""""""""
51+
-------------
3652
*Filter attributes and functions according to <mode>. Correct modes are:
3753
'PUB_ONLY' filter all non public attributes [DEFAULT], equivalent to PRIVATE+SPECIAL
3854
'ALL' no filter
@@ -43,127 +59,136 @@ Filtering and Scope
4359

4460

4561
--show-ancestors
46-
""""""""""""""""
62+
----------------
4763
*Show <ancestor> generations of ancestor classes not in <projects>.*
4864

4965
**Default:** ``None``
5066

5167

5268
--show-associated
53-
"""""""""""""""""
69+
-----------------
5470
*Show <association_level> levels of associated classes not in <projects>.*
5571

5672
**Default:** ``None``
5773

5874

5975
--show-builtin
60-
""""""""""""""
76+
--------------
6177
*Include builtin objects in representation of classes.*
6278

6379
**Default:** ``False``
6480

6581

6682
--show-stdlib
67-
"""""""""""""
83+
-------------
6884
*Include standard library objects in representation of classes.*
6985

7086
**Default:** ``False``
7187

7288

7389

7490

91+
.. _display-options:
92+
7593
Display Options
76-
---------------
94+
===============
95+
7796

7897
--color-palette
79-
"""""""""""""""
98+
---------------
8099
*Comma separated list of colors to use for the package depth coloring.*
81100

82101
**Default:** ``('#77AADD', '#99DDFF', '#44BB99', '#BBCC33', '#AAAA00', '#EEDD88', '#EE8866', '#FFAABB', '#DDDDDD')``
83102

84103

85104
--colorized
86-
"""""""""""
105+
-----------
87106
*Use colored output. Classes/modules of the same package get the same color.*
88107

89108
**Default:** ``False``
90109

91110

92111
--max-color-depth
93-
"""""""""""""""""
112+
-----------------
94113
*Use separate colors up to package depth of <depth>. Higher depths will reuse colors.*
95114

96115
**Default:** ``2``
97116

98117

99118
--module-names
100-
""""""""""""""
119+
--------------
101120
*Include module name in the representation of classes.*
102121

103122
**Default:** ``None``
104123

105124

106125
--no-standalone
107-
"""""""""""""""
126+
---------------
108127
*Only show nodes with connections.*
109128

110129
**Default:** ``False``
111130

112131

113132
--only-classnames
114-
"""""""""""""""""
133+
-----------------
115134
*Don't show attributes and methods in the class boxes; this disables -f values.*
116135

117136
**Default:** ``False``
118137

119138

120139

121140

141+
.. _output-control:
142+
122143
Output Control
123-
--------------
144+
==============
145+
124146

125147
--output
126-
""""""""
148+
--------
127149
*Create a *.<format> output file if format is available. Available formats are: .dot, .puml, .plantuml, .mmd, .html. Any other format will be tried to be created by using the 'dot' command line tool, which requires a graphviz installation. In this case, these additional formats are available (see `Graphviz output formats <https://graphviz.org/docs/outputs/>`_).*
128150

129151
**Default:** ``dot``
130152

131153

132154
--output-directory
133-
""""""""""""""""""
155+
------------------
134156
*Set the output directory path.*
135157

136158
**Default:** ``""``
137159

138160

139161

140162

163+
.. _project-configuration:
164+
141165
Project Configuration
142-
---------------------
166+
=====================
167+
143168

144169
--ignore
145-
""""""""
170+
--------
146171
*Files or directories to be skipped. They should be base names, not paths.*
147172

148173
**Default:** ``('CVS',)``
149174

150175

151176
--project
152-
"""""""""
177+
---------
153178
*Set the project name. This will later be appended to the output file names.*
154179

155180
**Default:** ``""``
156181

157182

158183
--source-roots
159-
""""""""""""""
184+
--------------
160185
*Add paths to the list of the source roots. Supports globbing patterns. The source root is an absolute path or a path relative to the current working directory used to determine a package namespace for modules located under the source root.*
161186

162187
**Default:** ``()``
163188

164189

165190
--verbose
166-
"""""""""
191+
---------
167192
*Makes pyreverse more verbose/talkative. Mostly useful for debugging.*
168193

169194
**Default:** ``False``
Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,40 @@
11
.. _pyreverse:
22

3+
=========
34
Pyreverse
4-
---------
5+
=========
56

6-
``pyreverse`` analyzes your source code and generates package and class diagrams.
7+
``pyreverse`` is a powerful tool that creates UML diagrams from your Python code. It helps you visualize:
78

8-
It supports output to ``.dot``/``.gv``, ``.puml``/``.plantuml`` (PlantUML) and ``.mmd``/``.html`` (MermaidJS) file formats.
9-
If Graphviz (or the ``dot`` command) is installed, all `output formats supported by Graphviz <https://graphviz.org/docs/outputs/>`_
10-
can be used as well. In this case, ``pyreverse`` first generates a temporary ``.gv`` file, which is then
11-
fed to Graphviz to generate the final image.
9+
- Package dependencies and structure
10+
- Class hierarchies and relationships
11+
- Method and attribute organization
1212

13-
Running Pyreverse
14-
'''''''''''''''''
13+
Output Formats
14+
==============
1515

16-
To run ``pyreverse``, use::
16+
``pyreverse`` supports multiple output formats:
1717

18-
pyreverse [options] <packages>
18+
* Native formats:
19+
* ``.dot``/``.gv`` (Graphviz)
20+
* ``.puml``/``.plantuml`` (PlantUML)
21+
* ``.mmd``/``.html`` (MermaidJS)
1922

20-
<packages> can also be a single Python module.
21-
To see a full list of the available options, run::
23+
* Additional formats (requires Graphviz installation):
24+
* All `Graphviz output formats <https://graphviz.org/docs/outputs/>`_ (PNG, SVG, PDF, etc.)
25+
* ``pyreverse`` first generates a temporary ``.gv`` file, which is then fed to Graphviz to generate the final image
2226

23-
pyreverse -h
27+
Getting Started
28+
===============
2429

25-
Example Output
26-
''''''''''''''
27-
28-
Example diagrams generated with the ``.puml`` output format are shown below.
29-
30-
Class Diagram
31-
.............
32-
33-
.. image:: ../../media/pyreverse_example_classes.png
34-
:width: 625
35-
:height: 589
36-
:alt: Class diagram generated by pyreverse
37-
:align: center
38-
39-
40-
Package Diagram
41-
...............
42-
43-
.. image:: ../../media/pyreverse_example_packages.png
44-
:width: 344
45-
:height: 177
46-
:alt: Package diagram generated by pyreverse
47-
:align: center
48-
49-
50-
Creating Class Diagrams for Specific Classes
51-
''''''''''''''''''''''''''''''''''''''''''''
52-
53-
In many cases creating a single diagram depicting all classes in the project yields a rather unwieldy, giant diagram.
54-
While limiting the input path to a single package or module can already help greatly to narrow down the scope, the ``-c`` option
55-
provides another way to create a class diagram focusing on a single class and its collaborators.
56-
For example, running::
57-
58-
pyreverse -ASmy -c pylint.checkers.classes.ClassChecker pylint
59-
60-
will generate the full class and package diagrams for ``pylint``, but will additionally generate a file ``pylint.checkers.classes.ClassChecker.dot``:
61-
62-
.. image:: ../../media/ClassChecker_diagram.png
63-
:width: 757
64-
:height: 1452
65-
:alt: Package diagram generated by pyreverse
66-
:align: center
30+
Check out the :doc:`configuration` guide to learn about available options, or see :doc:`output_examples`
31+
for sample diagrams and common use cases.
6732

6833
.. toctree::
69-
:maxdepth: 1
70-
:hidden:
34+
:maxdepth: 2
35+
:caption: Pyreverse
36+
:titlesonly:
37+
:hidden:
7138

72-
configuration
39+
configuration
40+
output_examples
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Example Output
2+
##############
3+
4+
Example diagrams generated with the ``.puml`` output format are shown below.
5+
6+
Package Diagram
7+
...............
8+
9+
.. image:: ../../media/pyreverse_example_packages.png
10+
:width: 344
11+
:height: 177
12+
:alt: Package diagram generated by pyreverse
13+
:align: center
14+
15+
Class Diagram
16+
.............
17+
18+
.. image:: ../../media/pyreverse_example_classes.png
19+
:width: 625
20+
:height: 589
21+
:alt: Class diagram generated by pyreverse
22+
:align: center
23+
24+
Creating Class Diagrams for Specific Classes
25+
''''''''''''''''''''''''''''''''''''''''''''
26+
27+
In many cases creating a single diagram depicting all classes in the project yields a rather unwieldy, giant diagram.
28+
While limiting the input path to a single package or module can already help greatly to narrow down the scope, the ``-c`` option
29+
provides another way to create a class diagram focusing on a single class and its collaborators.
30+
For example, running::
31+
32+
pyreverse -ASmy -c pylint.checkers.classes.ClassChecker pylint
33+
34+
will generate the full class and package diagrams for ``pylint``, but will additionally generate a file ``pylint.checkers.classes.ClassChecker.dot``:
35+
36+
.. image:: ../../media/ClassChecker_diagram.png
37+
:width: 757
38+
:height: 1452
39+
:alt: Package diagram generated by pyreverse
40+
:align: center

0 commit comments

Comments
 (0)