Skip to content

Commit ebae36e

Browse files
authored
Documentation for pyreverse and symilar (#4992)
* Add documentation for ``pyreverse`` and ``symilar`` * Rephrase "additional tools" to "additional commands" to be consistent with Readme * Replace some example diagrams with PlantUML ones and fix errors preventing the doc to build * Incorporate review feedback * Only hint to the ``-h`` option instead of including all options manually in the docs
1 parent dcd4887 commit ebae36e

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ Release date: TBA
8585

8686
* Fix ``no-self-use`` and ``docparams extension`` for async functions and methods.
8787

88+
* Add documentation for ``pyreverse`` and ``symilar``
89+
90+
Closes #4616
91+
8892

8993
What's New in Pylint 2.10.3?
9094
============================

doc/additional_commands/index.rst

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
Additional Commands
3+
===================
4+
5+
Pylint ships with some additional tools that can be executed from the command line once Pylint itself is installed.
6+
7+
8+
Pyreverse
9+
---------
10+
11+
``pyreverse`` analyzes your source code and generates package and class diagrams.
12+
It supports output to ``.dot``/``.gv``, ``.vcg`` and ``.puml``/``.plantuml`` (PlantUML) file formats.
13+
If Graphviz (or the ``dot`` command) is installed, all `output formats supported by Graphviz <https://graphviz.org/docs/outputs/>`_
14+
can be used as well. In this case, ``pyreverse`` first generates a temporary ``.gv`` file, which is then
15+
fed to Graphviz to generate the final image.
16+
17+
Running Pyreverse
18+
'''''''''''''''''
19+
20+
To run ``pyreverse``, use::
21+
22+
pyreverse [options] <packages>
23+
24+
<packages> can also be a single Python module.
25+
To see a full list of the available options, run::
26+
27+
pyreverse -h
28+
29+
30+
Example Output
31+
''''''''''''''
32+
33+
Example diagrams generated with the ``.puml`` output format are shown below.
34+
35+
Class Diagram
36+
.............
37+
38+
.. image:: ../media/pyreverse_example_classes.png
39+
:width: 625
40+
:height: 589
41+
:alt: Class diagram generated by pyreverse
42+
:align: center
43+
44+
45+
Package Diagram
46+
...............
47+
48+
.. image:: ../media/pyreverse_example_packages.png
49+
:width: 344
50+
:height: 177
51+
:alt: Package diagram generated by pyreverse
52+
:align: center
53+
54+
55+
Creating Class Diagrams for Specific Classes
56+
''''''''''''''''''''''''''''''''''''''''''''
57+
58+
In many cases creating a single diagram depicting all classes in the project yields a rather unwieldy, giant diagram.
59+
While limiting the input path to a single package or module can already help greatly to narrow down the scope, the ``-c`` option
60+
provides another way to create a class diagram focusing on a single class and its collaborators.
61+
For example, running::
62+
63+
pyreverse -ASmy -c pylint.checkers.classes.ClassChecker pylint
64+
65+
will generate the full class and package diagrams for ``pylint``, but will additionally generate a file ``pylint.checkers.classes.ClassChecker.dot``:
66+
67+
.. image:: ../media/ClassChecker_diagram.png
68+
:width: 757
69+
:height: 1452
70+
:alt: Package diagram generated by pyreverse
71+
:align: center
72+
73+
74+
Symilar
75+
-------
76+
77+
The console script ``symilar`` finds copy pasted blocks in a set of files. It provides a command line interface to the ``Similar`` class, which includes the logic for
78+
Pylint's ``duplicate-code`` message.
79+
It can be invoked with::
80+
81+
symilar [-d|--duplicates min_duplicated_lines] [-i|--ignore-comments] [--ignore-docstrings] [--ignore-imports] [--ignore-signatures] file1...
82+
83+
All files that shall be checked have to be passed in explicitly, e.g.::
84+
85+
symilar foo.py, bar.py, subpackage/spam.py, subpackage/eggs.py
86+
87+
``symilar`` produces output like the following::
88+
89+
17 similar lines in 2 files
90+
==tests/data/clientmodule_test.py:3
91+
==tests/data/suppliermodule_test.py:12
92+
class Ancestor:
93+
""" Ancestor method """
94+
__implements__ = (Interface,)
95+
cls_member = DoNothing()
96+
97+
def __init__(self, value):
98+
local_variable = 0
99+
self.attr = 'this method shouldn\'t have a docstring'
100+
self.__value = value
101+
102+
def get_value(self):
103+
""" nice docstring ;-) """
104+
return self.__value
105+
106+
def set_value(self, value):
107+
self.__value = value
108+
return 'this method shouldn\'t have a docstring'
109+
TOTAL lines=58 duplicates=17 percent=29.31

doc/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ refactored and can offer you details about the code's complexity.
1919
how_tos/index.rst
2020
technical_reference/index.rst
2121
development_guide/index.rst
22+
additional_commands/index.rst
2223

2324
faq
2425
backlinks

doc/media/ClassChecker_diagram.png

135 KB
Loading
29.4 KB
Loading
6.08 KB
Loading

0 commit comments

Comments
 (0)