|
| 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 |
0 commit comments