Source code for gpe.utils_docs
"""Utilities for the documentation."""
import graphviz
[docs]
def get_inheritance_graph(cls, mro=True):
"""Return an inheritance diagram of `cls`.
Arguments
---------
mro : bool
Indicate the method-resolution order in red.
"""
dot = graphviz.Digraph(
format="png", graph_attr=dict(rankdir="LR"), node_attr=dict(shape="box")
)
for c in cls.mro():
for b in c.__bases__:
if b is object:
continue
dot.edge(b.__name__, c.__name__)
if mro:
for n, (c0, c1) in enumerate(zip(cls.mro(), cls.mro()[1:])):
if c1 is object:
continue
dot.edge(
c0.__name__,
c1.__name__,
color="red",
constraint="false",
taillabel=str(n + 1),
)
return dot