sphinx-uml#

PyPI Build Documentation ReadTheDocs

Overview#

sphinx-uml is a python package that provides:

  • A Sphinx extension, called using .. uml, which generates UML diagrams from python modules, just like sphinx-pyreverse.

  • The pyreverse2 command, that extends pyreverse provided by pylint.

Compared to sphinx-pyreverse, sphinx-uml outputs enriched dot or SVG UML diagrams.

  • responsive to light/black Sphinx themes (as pydata);

  • if the HTML address is known, the class/attribute/method names can be clicked to browse the corresponding documentation page.

Features#

.. uml directive#

UML diagrams can be obtained by using the .. uml directive.

Example:

.. uml:: example.module.b1
    :caption: UML diagram of ``example.module.b1``
    :classes:
    :packages:

This toy example shows how to use the .. uml directive in a Sphinx documentation using sphinx.ext.autodoc and sphinx.ext.autosummary.

pyreverse2#

The pyreverse2 behaves like the original pyreverse command with two main differences:

  • --ouput: svg and dot are the only supported output formats;

  • --sphinx-html-dir can be used to indicate where is the HTML root directory.

Example: In the example below, we assume that:

  • the example package has been installed

  • the documentation has been built in $HOME/git/sphinx-pyreverse/example/docs/_build/html/

# Generate the UML diagram for each value of x
for x in example example.module example.module.submodule example.module.submodule.c1
do
   pyreverse2 \
      --sphinx-html-dir $HOME/git/sphinx-uml/example/docs/_build/html/ \
      --output svg \
      --project $x \
      $x
   # The previous command outputs {classes,packages}_$o.svg
done

Documentation#