Skip to content

Commit

Permalink
sphinxext: backport autosummary changes from trunk
Browse files Browse the repository at this point in the history
r6686, r6687, r6690
  • Loading branch information
pv committed Mar 17, 2009
1 parent c59d898 commit d0d2afa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions doc/sphinxext/autosummary.py
Expand Up @@ -129,7 +129,8 @@ def autosummary_directive(dirname, arguments, options, content, lineno,
"""

names = []
names += [x.strip() for x in content if x.strip()]
names += [x.strip().split()[0] for x in content
if x.strip() and re.search(r'^[a-zA-Z_]', x.strip()[0])]

table, warnings, real_names = get_autosummary(names, state,
'nosignatures' in options)
Expand Down Expand Up @@ -189,8 +190,8 @@ def get_autosummary(names, state, no_signatures=False):
table = nodes.table('')
group = nodes.tgroup('', cols=2)
table.append(group)
group.append(nodes.colspec('', colwidth=30))
group.append(nodes.colspec('', colwidth=70))
group.append(nodes.colspec('', colwidth=10))
group.append(nodes.colspec('', colwidth=90))
body = nodes.tbody('')
group.append(body)

Expand Down Expand Up @@ -222,20 +223,21 @@ def append_row(*column_texts):
else:
title = ""

col1 = ":obj:`%s <%s>`" % (name, real_name)
col1 = u":obj:`%s <%s>`" % (name, real_name)
if doc['Signature']:
sig = re.sub('^[a-zA-Z_0-9.-]*', '', doc['Signature'])
sig = re.sub('^[^(\[]*', '', doc['Signature'].strip())
if '=' in sig:
# abbreviate optional arguments
sig = re.sub(r', ([a-zA-Z0-9_]+)=', r'[, \1=', sig, count=1)
sig = re.sub(r'\(([a-zA-Z0-9_]+)=', r'([\1=', sig, count=1)
sig = re.sub(r'=[^,)]+,', ',', sig)
sig = re.sub(r'=[^,)]+\)$', '])', sig)
# shorten long strings
sig = re.sub(r'(\[.{16,16}[^,)]*?),.*?\]\)', r'\1, ...])', sig)
sig = re.sub(r'(\[.{16,16}[^,]*?),.*?\]\)', r'\1, ...])', sig)
else:
sig = re.sub(r'(\(.{16,16}[^,)]*?),.*?\)', r'\1, ...)', sig)
col1 += " " + sig
sig = re.sub(r'(\(.{16,16}[^,]*?),.*?\)', r'\1, ...)', sig)
# make signature contain non-breaking spaces
col1 += u"\\ \u00a0" + unicode(sig).replace(u" ", u"\u00a0")
col2 = title
append_row(col1, col2)

Expand Down

0 comments on commit d0d2afa

Please sign in to comment.