Source

Create Graphviz graphs from sphinx-apidoc / add_graphviz_capability.patch

Full commit
# HG changeset patch
# Parent 24ad0c778dade8e81b92df603a5e964ee26332ed
# User mcagl

diff -r 24ad0c778dad sphinx/apidoc.py
--- a/sphinx/apidoc.py	Tue May 08 12:54:57 2012 +0200
+++ b/sphinx/apidoc.py	Thu May 10 12:37:41 2012 +0200
@@ -68,9 +68,12 @@
     return '%s\n%s\n\n' % (text, underlining)
 
 
-def format_directive(module, package=None):
+def format_directive(module, package=None, opts=None):
     """Create the automodule directive and add the options."""
-    directive = '.. automodule:: %s\n' % makename(package, module)
+    directive = ''
+    if opts.graphs:
+        directive += '.. inheritance-diagram:: %s\n' % makename(package, module)
+    directive += '.. automodule:: %s\n' % makename(package, module)
     for option in OPTIONS:
         directive += '    :%s:\n' % option
     return directive
@@ -80,7 +83,7 @@
     """Build the text of the file and write the file."""
     text = format_heading(1, '%s Module' % module)
     #text += format_heading(2, ':mod:`%s` Module' % module)
-    text += format_directive(module, package)
+    text += format_directive(module, package, opts)
     write_file(makename(package, module), text, opts)
 
 
@@ -101,7 +104,7 @@
             heading = ':mod:`%s` Module' % py_file
         text += format_heading(2, heading)
         text += format_directive(is_package and subroot or py_path,
-                                 master_package)
+                                 master_package, opts)
         text += '\n'
 
     # build a list of directories that are packages (contain an INITPY file)
@@ -250,6 +253,8 @@
                       help='Run the script without creating files')
     parser.add_option('-T', '--no-toc', action='store_true', dest='notoc',
                       help='Don\'t create a table of contents file')
+    parser.add_option('-G', '--graphs', action='store_true', dest='graphs',
+                      help='Generate inheritance graphs using Graphviz')
     parser.add_option('-s', '--suffix', action='store', dest='suffix',
                       help='file suffix (default: rst)', default='rst')
     parser.add_option('-F', '--full', action='store_true', dest='full',
@@ -308,11 +313,16 @@
             epub = True,
             ext_autodoc = True,
             ext_viewcode = True,
+            ext_graphviz = False,
+            ext_inheritance_diagram = False,
             makefile = True,
             batchfile = True,
             mastertocmaxdepth = opts.maxdepth,
             mastertoctree = text,
         )
+        if opts.graphs:
+            d['ext_graphviz'] = True
+            d['ext_inheritance_diagram'] = True
         if not opts.dryrun:
             qs.generate(d, silent=True, overwrite=opts.force)
     elif not opts.notoc:
diff -r 24ad0c778dad sphinx/quickstart.py
--- a/sphinx/quickstart.py	Tue May 08 12:54:57 2012 +0200
+++ b/sphinx/quickstart.py	Thu May 10 12:37:41 2012 +0200
@@ -976,7 +976,8 @@
     d['extensions'] = ', '.join(
         repr('sphinx.ext.' + name)
         for name in ('autodoc', 'doctest', 'intersphinx', 'todo', 'coverage',
-                     'pngmath', 'mathjax', 'ifconfig', 'viewcode')
+                     'pngmath', 'mathjax', 'ifconfig', 'viewcode', 'graphviz',
+                     'inheritance_diagram')
         if d.get('ext_' + name))
     d['copyright'] = time.strftime('%Y') + ', ' + d['author']
     d['author_texescaped'] = unicode(d['author']).\