2009-03-04 17:14:29 -06:00
|
|
|
.. highlight:: rest
|
|
|
|
|
2009-03-04 17:17:14 -06:00
|
|
|
:mod:`sphinx.ext.inheritance_diagram` -- Include inheritance diagrams
|
|
|
|
=====================================================================
|
2009-03-04 17:14:29 -06:00
|
|
|
|
|
|
|
.. module:: sphinx.ext.inheritance_diagram
|
|
|
|
:synopsis: Support for displaying inheritance diagrams via graphviz.
|
|
|
|
|
|
|
|
.. versionadded:: 0.6
|
|
|
|
|
|
|
|
This extension allows you to include inheritance diagrams, rendered via the
|
|
|
|
:mod:`Graphviz extension <sphinx.ext.graphviz>`.
|
|
|
|
|
|
|
|
It adds this directive:
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: inheritance-diagram
|
2009-03-04 17:14:29 -06:00
|
|
|
|
|
|
|
This directive has one or more arguments, each giving a module or class
|
|
|
|
name. Class names can be unqualified; in that case they are taken to exist
|
2010-08-05 06:39:23 -05:00
|
|
|
in the currently described module (see :rst:dir:`py:module`).
|
2009-03-04 17:14:29 -06:00
|
|
|
|
|
|
|
For each given class, and each class in each given module, the base classes
|
|
|
|
are determined. Then, from all classes and their base classes, a graph is
|
|
|
|
generated which is then rendered via the graphviz extension to a directed
|
|
|
|
graph.
|
|
|
|
|
|
|
|
This directive supports an option called ``parts`` that, if given, must be an
|
|
|
|
integer, advising the directive to remove that many parts of module names
|
|
|
|
from the displayed names. (For example, if all your class names start with
|
|
|
|
``lib.``, you can give ``:parts: 1`` to remove that prefix from the displayed
|
|
|
|
node names.)
|
|
|
|
|
2011-01-07 15:35:57 -06:00
|
|
|
It also supports a ``private-bases`` flag option; if given, private base
|
|
|
|
classes (those whose name starts with ``_``) will be included.
|
|
|
|
|
2016-03-10 22:20:05 -06:00
|
|
|
You can use ``caption`` option to give a caption to the diagram.
|
|
|
|
|
2011-01-07 15:35:57 -06:00
|
|
|
.. versionchanged:: 1.1
|
|
|
|
Added ``private-bases`` option; previously, all bases were always
|
|
|
|
included.
|
|
|
|
|
2016-03-10 22:20:05 -06:00
|
|
|
.. versionchanged:: 1.5
|
2016-07-07 08:36:44 -05:00
|
|
|
Added ``caption`` option
|
2016-03-10 22:20:05 -06:00
|
|
|
|
2016-01-21 03:11:06 -06:00
|
|
|
It also supports a ``top-classes`` option which requires one or more class
|
|
|
|
names separated by comma. If specified inheritance traversal will stop at the
|
|
|
|
specified class names. Given the following Python module::
|
|
|
|
|
|
|
|
"""
|
|
|
|
A
|
|
|
|
/ \
|
|
|
|
B C
|
|
|
|
/ \ / \
|
|
|
|
E D F
|
|
|
|
"""
|
|
|
|
|
2018-09-11 08:48:35 -05:00
|
|
|
class A:
|
2016-01-21 03:11:06 -06:00
|
|
|
pass
|
|
|
|
|
|
|
|
class B(A):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class C(A):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class D(B, C):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class E(B):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class F(C):
|
|
|
|
pass
|
|
|
|
|
|
|
|
If you have specified a module in the inheritance diagram like this::
|
|
|
|
|
2018-01-12 20:09:27 -06:00
|
|
|
.. inheritance-diagram:: dummy.test
|
|
|
|
:top-classes: dummy.test.B, dummy.test.C
|
2016-01-21 03:11:06 -06:00
|
|
|
|
|
|
|
any base classes which are ancestors to ``top-classes`` and are also defined
|
|
|
|
in the same module will be rendered as stand alone nodes. In this example
|
|
|
|
class A will be rendered as stand alone node in the graph. This is a known
|
|
|
|
issue due to how this extension works internally.
|
|
|
|
|
|
|
|
If you don't want class A (or any other ancestors) to be visible then specify
|
|
|
|
only the classes you would like to generate the diagram for like this::
|
|
|
|
|
2018-01-12 20:09:27 -06:00
|
|
|
.. inheritance-diagram:: dummy.test.D dummy.test.E dummy.test.F
|
|
|
|
:top-classes: dummy.test.B, dummy.test.C
|
2016-01-21 03:11:06 -06:00
|
|
|
|
|
|
|
.. versionchanged:: 1.7
|
|
|
|
Added ``top-classes`` option to limit the scope of inheritance graphs.
|
2009-03-04 17:14:29 -06:00
|
|
|
|
2018-06-08 11:27:13 -05:00
|
|
|
|
|
|
|
Configuration
|
|
|
|
-------------
|
2009-03-04 17:14:29 -06:00
|
|
|
|
|
|
|
.. confval:: inheritance_graph_attrs
|
|
|
|
|
|
|
|
A dictionary of graphviz graph attributes for inheritance diagrams.
|
|
|
|
|
2009-11-08 03:18:35 -06:00
|
|
|
For example::
|
|
|
|
|
|
|
|
inheritance_graph_attrs = dict(rankdir="LR", size='"6.0, 8.0"',
|
|
|
|
fontsize=14, ratio='compress')
|
|
|
|
|
2009-03-04 17:14:29 -06:00
|
|
|
.. confval:: inheritance_node_attrs
|
|
|
|
|
|
|
|
A dictionary of graphviz node attributes for inheritance diagrams.
|
|
|
|
|
2009-11-08 03:18:35 -06:00
|
|
|
For example::
|
|
|
|
|
|
|
|
inheritance_node_attrs = dict(shape='ellipse', fontsize=14, height=0.75,
|
|
|
|
color='dodgerblue1', style='filled')
|
|
|
|
|
2009-03-04 17:14:29 -06:00
|
|
|
.. confval:: inheritance_edge_attrs
|
|
|
|
|
|
|
|
A dictionary of graphviz edge attributes for inheritance diagrams.
|
2017-07-26 14:07:25 -05:00
|
|
|
|
|
|
|
.. confval:: inheritance_alias
|
|
|
|
|
|
|
|
Allows mapping the full qualified name of the class to custom values
|
|
|
|
(useful when exposing the underlying path of a class is not desirable,
|
|
|
|
e.g. it's a private class and should not be instantiated by the user).
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
inheritance_alias = {'_pytest.Magic': 'pytest.Magic'}
|