Hello devs, I'm starting to use Sphinx to (automatically) document a Python project.
I didn't find a way to automatically add the inheritance graphs directly from the sphinx-apidoc invocation, so yesterday I did a little patch (involving apidoc.py and quickstart.py). I'm not very used to mercurial and I thought that forking on bitbucket was too much for a single patch, so I did a patch queue. At the moment of sending a pull request, bitbucket offered me only the possibility to make the pull request from my repo to.... my repo. Here it is the link: https://bitbucket.org/mcagl/create-graphviz-graphs-from-sphinx-apidoc So I'm sending here the patch, following the advice written in the bottom of the Sphinx README. The patch is done against the 24ad0c778dad commit. Maybe I did something wrong, but this patch adds the option -G (--graphs) to sphinx-apidoc, and the effect is to add .. inheritance-diagram:: foo to the *.rst files, and the two needed extensions to conf.py (made by patching quickstart.py) I hope that my little patch will be useful, best regards, Mark Caglienzi -- . ''`. | GPG Public Key : 0xCD542422 - Download it from http://is.gd/fOa7Vm : :' : | GPG Fingerprint : 0823 A40D F31B 67A8 5621 AD32 E293 A2EB CD54 2422 `. `'` | Powered by Debian GNU/Linux, http://www.debian.org `- | Try not. Do, or do not. There is no try. - Master Yoda, TESB.
diff -cB before/apidoc.py after/apidoc.py *** before/apidoc.py 2012-05-10 07:13:42.000000000 +0200 --- after/apidoc.py 2012-05-10 07:21:13.000000000 +0200 *************** *** 68,76 **** return '%s\n%s\n\n' % (text, underlining) ! def format_directive(module, package=None): """Create the automodule directive and add the options.""" ! directive = '.. automodule:: %s\n' % makename(package, module) for option in OPTIONS: directive += ' :%s:\n' % option return directive --- 68,79 ---- return '%s\n%s\n\n' % (text, underlining) ! def format_directive(module, package=None, opts=None): """Create the automodule directive and add the options.""" ! 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,86 **** """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) write_file(makename(package, module), text, opts) --- 83,89 ---- """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, opts) write_file(makename(package, module), text, opts) *************** *** 101,107 **** heading = ':mod:`%s` Module' % py_file text += format_heading(2, heading) text += format_directive(is_package and subroot or py_path, ! master_package) text += '\n' # build a list of directories that are packages (contain an INITPY file) --- 104,110 ---- heading = ':mod:`%s` Module' % py_file text += format_heading(2, heading) text += format_directive(is_package and subroot or py_path, ! master_package, opts) text += '\n' # build a list of directories that are packages (contain an INITPY file) *************** *** 250,255 **** --- 253,260 ---- 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,318 **** --- 313,328 ---- 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 -cB before/quickstart.py after/quickstart.py *** before/quickstart.py 2012-05-10 07:13:47.000000000 +0200 --- after/quickstart.py 2012-05-10 07:22:34.000000000 +0200 *************** *** 976,982 **** d['extensions'] = ', '.join( repr('sphinx.ext.' + name) for name in ('autodoc', 'doctest', 'intersphinx', 'todo', 'coverage', ! 'pngmath', 'mathjax', 'ifconfig', 'viewcode') if d.get('ext_' + name)) d['copyright'] = time.strftime('%Y') + ', ' + d['author'] d['author_texescaped'] = unicode(d['author']).\ --- 976,983 ---- d['extensions'] = ', '.join( repr('sphinx.ext.' + name) for name in ('autodoc', 'doctest', 'intersphinx', 'todo', 'coverage', ! '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']).\
signature.asc
Description: Digital signature