From 73ae2f9c940db3be706197971807e7f1355b6234 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 21 Mar 2009 00:34:46 +0200 Subject: [PATCH] Some autosummary fixes --- doc/ext/autosummary.rst | 4 ++++ sphinx/ext/autosummary/__init__.py | 36 +++++++++++++++++------------- sphinx/ext/autosummary/generate.py | 4 ++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/doc/ext/autosummary.rst b/doc/ext/autosummary.rst index a9255857b..7ad46d272 100644 --- a/doc/ext/autosummary.rst +++ b/doc/ext/autosummary.rst @@ -6,4 +6,8 @@ .. module:: sphinx.ext.autosummary :synopsis: Generate autodoc summaries +This extension can be used to generate function/method/attribute +summary lists, similar to those output eg. by Epydoc and other API doc +generation tools. + TBW. diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 3d260fd20..df46b71cb 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -68,6 +68,8 @@ from sphinx import addnodes, roles from sphinx.util import patfilter from sphinx.util.compat import Directive +from sphinx.ext.autodoc import FunctionDocumenter + # -- autosummary_toc node ------------------------------------------------------ @@ -132,7 +134,7 @@ class Autosummary(Directive): names += [x.strip() for x in self.content if x.strip()] table, warnings, real_names = get_autosummary( - names, self.state, 'nosignatures' in self.options) + names, self, 'nosignatures' in self.options) node = table env = self.state.document.settings.env @@ -168,7 +170,7 @@ class Autosummary(Directive): return warnings + [node] -def get_autosummary(names, state, no_signatures=False): +def get_autosummary(names, directive, no_signatures=False): """ Generate a proper table node for autosummary:: directive. @@ -176,14 +178,12 @@ def get_autosummary(names, state, no_signatures=False): table. *document* is the Docutils document object. """ + state = directive.state document = state.document real_names = {} warnings = [] - prefixes = [''] - prefixes.insert(0, document.settings.env.currmodule) - table = nodes.table('') group = nodes.tgroup('', cols=2) table.append(group) @@ -203,19 +203,25 @@ def get_autosummary(names, state, no_signatures=False): body.append(row) for name in names: - try: - obj, real_name = import_by_name(name, prefixes=prefixes) - except ImportError: - warnings.append(document.reporter.warning( - 'failed to import %s' % name)) - append_row(':obj:`%s`' % name, '') - continue + documenter = FunctionDocumenter(self, name) + documenter.parse_name() - real_names[name] = real_name + real_names[name] = documenter.fullname + + sig = documenter.format_signature() + if sig: + pass + else: + sig = '' + + doc = list(documenter.process_doc([documenter.get_doc()])) + if doc: + title = doc[0] + else: + title = '' - title = '' qualifier = 'obj' - col1 = ':'+qualifier+':`%s <%s>`' % (name, real_name) + col1 = ':' + qualifier + r':`%s <%s>`\ %s' % (name, real_name, sig) col2 = title append_row(col1, col2) diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index c21d71ac5..0026d21dd 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -211,10 +211,10 @@ def get_documented(filenames): return documented -def main(argv): +def main(): usage = 'usage: %s [-o output_dir] [-s suffix] sourcefile ...' % sys.argv[0] try: - opts, args = getopt.getopt(argv[1:], 'o:s:') + opts, args = getopt.getopt(sys.argv[1:], 'o:s:') except getopt.error: print >>sys.stderr, usage return 1