r63836 - in doctools/trunk: CHANGES sphinx/directives/desc.py sphinx/ext/autodoc.py

Author: georg.brandl Date: Sat May 31 18:58:22 2008 New Revision: 63836 Log: Fix handling of autoclass directives' module names. Modified: doctools/trunk/CHANGES doctools/trunk/sphinx/directives/desc.py doctools/trunk/sphinx/ext/autodoc.py Modified: doctools/trunk/CHANGES ============================================================================== --- doctools/trunk/CHANGES (original) +++ doctools/trunk/CHANGES Sat May 31 18:58:22 2008 @@ -61,6 +61,9 @@ * Provide the standard "class" directive as "cssclass"; else it is shadowed by the Sphinx-defined directive. +* Fix the handling of explicit module names given to autoclass directives. + They now show up with the correct module name in the generated docs. + Release 0.3 (May 6, 2008) ========================= Modified: doctools/trunk/sphinx/directives/desc.py ============================================================================== --- doctools/trunk/sphinx/directives/desc.py (original) +++ doctools/trunk/sphinx/directives/desc.py Sat May 31 18:58:22 2008 @@ -20,41 +20,41 @@ # ------ information units --------------------------------------------------------- -def desc_index_text(desctype, currmodule, name): +def desc_index_text(desctype, module, name): if desctype == 'function': - if not currmodule: + if not module: return '%s() (built-in function)' % name - return '%s() (in module %s)' % (name, currmodule) + return '%s() (in module %s)' % (name, module) elif desctype == 'data': - if not currmodule: + if not module: return '%s (built-in variable)' % name - return '%s (in module %s)' % (name, currmodule) + return '%s (in module %s)' % (name, module) elif desctype == 'class': - return '%s (class in %s)' % (name, currmodule) + return '%s (class in %s)' % (name, module) elif desctype == 'exception': return name elif desctype == 'method': try: clsname, methname = name.rsplit('.', 1) except ValueError: - if currmodule: - return '%s() (in module %s)' % (name, currmodule) + if module: + return '%s() (in module %s)' % (name, module) else: return '%s()' % name - if currmodule: - return '%s() (%s.%s method)' % (methname, currmodule, clsname) + if module: + return '%s() (%s.%s method)' % (methname, module, clsname) else: return '%s() (%s method)' % (methname, clsname) elif desctype == 'attribute': try: clsname, attrname = name.rsplit('.', 1) except ValueError: - if currmodule: - return '%s (in module %s)' % (name, currmodule) + if module: + return '%s (in module %s)' % (name, module) else: return name - if currmodule: - return '%s (%s.%s attribute)' % (attrname, currmodule, clsname) + if module: + return '%s (%s.%s attribute)' % (attrname, module, clsname) else: return '%s (%s attribute)' % (attrname, clsname) elif desctype == 'opcode': @@ -82,7 +82,7 @@ py_paramlist_re = re.compile(r'([\[\],])') # split at '[', ']' and ',' -def parse_py_signature(signode, sig, desctype, env): +def parse_py_signature(signode, sig, desctype, module, env): """ Transform a python signature into RST nodes. Return (fully qualified name of the thing, classname if any). @@ -118,8 +118,8 @@ # exceptions are a special case, since they are documented in the # 'exceptions' module. elif add_module and env.config.add_module_names and \ - env.currmodule and env.currmodule != 'exceptions': - nodetext = env.currmodule + '.' + module and module != 'exceptions': + nodetext = module + '.' signode += addnodes.desc_classname(nodetext, nodetext) signode += addnodes.desc_name(name, name) @@ -284,6 +284,7 @@ signatures = map(lambda s: s.strip().replace('\\', ''), arguments[0].split('\n')) names = [] clsname = None + module = options.get('module', env.currmodule) for i, sig in enumerate(signatures): # add a signature node for each signature in the current unit # and add a reference target for it @@ -294,7 +295,7 @@ try: if desctype in ('function', 'data', 'class', 'exception', 'method', 'attribute'): - name, clsname = parse_py_signature(signode, sig, desctype, env) + name, clsname = parse_py_signature(signode, sig, desctype, module, env) elif desctype in ('cfunction', 'cmember', 'cmacro', 'ctype', 'cvar'): name = parse_c_signature(signode, sig, desctype) elif desctype == 'opcode': @@ -347,7 +348,7 @@ # only add target and index entry if this is the first description of the # function name in this desc block if not noindex and name not in names: - fullname = (env.currmodule and env.currmodule + '.' or '') + name + fullname = (module and module + '.' or '') + name # note target if fullname not in state.document.ids: signode['names'].append(fullname) @@ -358,7 +359,7 @@ names.append(name) env.note_index_entry('single', - desc_index_text(desctype, env.currmodule, name), + desc_index_text(desctype, module, name), fullname, fullname) subnode = addnodes.desc_content() @@ -382,7 +383,8 @@ desc_directive.content = 1 desc_directive.arguments = (1, 0, 1) -desc_directive.options = {'noindex': directives.flag} +desc_directive.options = {'noindex': directives.flag, + 'module': directives.unchanged} desctypes = [ # the Python ones Modified: doctools/trunk/sphinx/ext/autodoc.py ============================================================================== --- doctools/trunk/sphinx/ext/autodoc.py (original) +++ doctools/trunk/sphinx/ext/autodoc.py Sat May 31 18:58:22 2008 @@ -184,6 +184,10 @@ except Exception: args = '' result.append(indent + '.. %s:: %s%s' % (what, qualname, args), '<autodoc>') + if what != 'module': + # Be explicit about the module, this is necessary since .. class:: doesn't + # support a prepended module name + result.append(indent + ' :module: %s' % mod, '<autodoc>') result.append('', '<autodoc>') # the module directive doesn't have content
participants (1)
-
georg.brandl