summaryrefslogtreecommitdiff
path: root/sphinx/pycode
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-02-28 11:39:13 +0100
committerGeorg Brandl <georg@python.org>2010-02-28 11:39:13 +0100
commitffe393b1b0a47d28c770668378ccff750fa82be3 (patch)
tree7338193901f847626069f9805128bb24f24bf01f /sphinx/pycode
parent887ee5f5291ccf51bdddf137a4cd8df20b3482a5 (diff)
downloadsphinx-ffe393b1b0a47d28c770668378ccff750fa82be3.tar.gz
#187: Added support for source ordering of members in autodoc, with ``autodoc_member_order = 'bysource'``.
Diffstat (limited to 'sphinx/pycode')
-rw-r--r--sphinx/pycode/__init__.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py
index 73c2042f..63303a85 100644
--- a/sphinx/pycode/__init__.py
+++ b/sphinx/pycode/__init__.py
@@ -58,9 +58,17 @@ class AttrDocVisitor(nodes.NodeVisitor):
self.encoding = encoding
self.namespace = []
self.collected = {}
+ self.tagnumber = 0
+ self.tagorder = {}
+
+ def add_tag(self, name):
+ name = '.'.join(self.namespace + [name])
+ self.tagorder[name] = self.tagnumber
+ self.tagnumber += 1
def visit_classdef(self, node):
"""Visit a class."""
+ self.add_tag(node[1].value)
self.namespace.append(node[1].value)
self.generic_visit(node)
self.namespace.pop()
@@ -68,6 +76,7 @@ class AttrDocVisitor(nodes.NodeVisitor):
def visit_funcdef(self, node):
"""Visit a function (or method)."""
# usually, don't descend into functions -- nothing interesting there
+ self.add_tag(node[1].value)
if node[1].value == '__init__':
# however, collect attributes set in __init__ methods
self.in_init += 1
@@ -91,8 +100,7 @@ class AttrDocVisitor(nodes.NodeVisitor):
prefix = pnode.get_prefix()
prefix = prefix.decode(self.encoding)
docstring = prepare_commentdoc(prefix)
- if docstring:
- self.add_docstring(node, docstring)
+ self.add_docstring(node, docstring)
def visit_simple_stmt(self, node):
"""Visit a docstring statement which may have an assignment before."""
@@ -133,9 +141,11 @@ class AttrDocVisitor(nodes.NodeVisitor):
continue
else:
name = target.value
- namespace = '.'.join(self.namespace)
- if namespace.startswith(self.scope):
- self.collected[namespace, name] = docstring
+ self.add_tag(name)
+ if docstring:
+ namespace = '.'.join(self.namespace)
+ if namespace.startswith(self.scope):
+ self.collected[namespace, name] = docstring
class ModuleAnalyzer(object):
@@ -197,6 +207,7 @@ class ModuleAnalyzer(object):
self.parsetree = None
# will be filled by find_attr_docs()
self.attr_docs = None
+ self.tagorder = None
# will be filled by find_tags()
self.tags = None
@@ -234,6 +245,7 @@ class ModuleAnalyzer(object):
attr_visitor = AttrDocVisitor(number2name, scope, self.encoding)
attr_visitor.visit(self.parsetree)
self.attr_docs = attr_visitor.collected
+ self.tagorder = attr_visitor.tagorder
# now that we found everything we could in the tree, throw it away
# (it takes quite a bit of memory for large modules)
self.parsetree = None