mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Closes #1302: Fix regression in :mod:sphinx.ext.inheritance_diagram
when documenting classes that can't be pickled.
This commit is contained in:
parent
310b4fb806
commit
3f7ecbde96
3
CHANGES
3
CHANGES
@ -104,6 +104,9 @@ Bugs fixed
|
|||||||
|
|
||||||
* #979, #1266: Fix exclude handling in ``sphinx-apidoc``.
|
* #979, #1266: Fix exclude handling in ``sphinx-apidoc``.
|
||||||
|
|
||||||
|
* #1302: Fix regression in :mod:`sphinx.ext.inheritance_diagram` when
|
||||||
|
documenting classes that can't be pickled.
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
@ -178,6 +178,9 @@ def render_dot(self, code, options, format, prefix='graphviz'):
|
|||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise GraphvizError('dot exited with error:\n[stderr]\n%s\n'
|
raise GraphvizError('dot exited with error:\n[stderr]\n%s\n'
|
||||||
'[stdout]\n%s' % (stderr, stdout))
|
'[stdout]\n%s' % (stderr, stdout))
|
||||||
|
if not path.isfile(outfn):
|
||||||
|
raise GraphvizError('dot did not produce an output file:\n[stderr]\n%s\n'
|
||||||
|
'[stdout]\n%s' % (stderr, stdout))
|
||||||
return relfn, outfn
|
return relfn, outfn
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,8 +154,18 @@ class InheritanceGraph(object):
|
|||||||
nodename = self.class_name(cls, parts)
|
nodename = self.class_name(cls, parts)
|
||||||
fullname = self.class_name(cls, 0)
|
fullname = self.class_name(cls, 0)
|
||||||
|
|
||||||
|
# Use first line of docstring as tooltip, if available
|
||||||
|
tooltip = None
|
||||||
|
try:
|
||||||
|
if cls.__doc__:
|
||||||
|
doc = cls.__doc__.strip().split("\n")[0]
|
||||||
|
if doc:
|
||||||
|
tooltip = '"%s"' % doc.replace('"', '\\"')
|
||||||
|
except Exception: # might raise AttributeError for strange classes
|
||||||
|
pass
|
||||||
|
|
||||||
baselist = []
|
baselist = []
|
||||||
all_classes[cls] = (nodename, fullname, baselist)
|
all_classes[cls] = (nodename, fullname, baselist, tooltip)
|
||||||
for base in cls.__bases__:
|
for base in cls.__bases__:
|
||||||
if not show_builtins and base in builtins:
|
if not show_builtins and base in builtins:
|
||||||
continue
|
continue
|
||||||
@ -168,7 +178,7 @@ class InheritanceGraph(object):
|
|||||||
for cls in classes:
|
for cls in classes:
|
||||||
recurse(cls)
|
recurse(cls)
|
||||||
|
|
||||||
return all_classes
|
return all_classes.values()
|
||||||
|
|
||||||
def class_name(self, cls, parts=0):
|
def class_name(self, cls, parts=0):
|
||||||
"""Given a class object, return a fully-qualified name.
|
"""Given a class object, return a fully-qualified name.
|
||||||
@ -188,7 +198,7 @@ class InheritanceGraph(object):
|
|||||||
|
|
||||||
def get_all_class_names(self):
|
def get_all_class_names(self):
|
||||||
"""Get all of the class names involved in the graph."""
|
"""Get all of the class names involved in the graph."""
|
||||||
return [fullname for (_, fullname, _) in self.class_info.values()]
|
return [fullname for (_, fullname, _, _) in self.class_info]
|
||||||
|
|
||||||
# These are the default attrs for graphviz
|
# These are the default attrs for graphviz
|
||||||
default_graph_attrs = {
|
default_graph_attrs = {
|
||||||
@ -241,17 +251,13 @@ class InheritanceGraph(object):
|
|||||||
res.append('digraph %s {\n' % name)
|
res.append('digraph %s {\n' % name)
|
||||||
res.append(self._format_graph_attrs(g_attrs))
|
res.append(self._format_graph_attrs(g_attrs))
|
||||||
|
|
||||||
for cls, (name, fullname, bases) in sorted(self.class_info.items()):
|
for name, fullname, bases, tooltip in sorted(self.class_info):
|
||||||
# Write the node
|
# Write the node
|
||||||
this_node_attrs = n_attrs.copy()
|
this_node_attrs = n_attrs.copy()
|
||||||
if fullname in urls:
|
if fullname in urls:
|
||||||
this_node_attrs['URL'] = '"%s"' % urls[fullname]
|
this_node_attrs['URL'] = '"%s"' % urls[fullname]
|
||||||
# Use first line of docstring as tooltip, if available
|
if tooltip:
|
||||||
if cls.__doc__:
|
this_node_attrs['tooltip'] = tooltip
|
||||||
doc = cls.__doc__.strip().split("\n")[0]
|
|
||||||
if doc:
|
|
||||||
doc = doc.replace('"', '\\"')
|
|
||||||
this_node_attrs['tooltip'] = '"%s"' % doc
|
|
||||||
res.append(' "%s" [%s];\n' %
|
res.append(' "%s" [%s];\n' %
|
||||||
(name, self._format_node_attrs(this_node_attrs)))
|
(name, self._format_node_attrs(this_node_attrs)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user