Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions sphinxarg/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def print_subcommands(data, nested_content, markDownHelp=False, settings=None):
return items


def ensureUniqueIDs(items):
def ensureUniqueIDs(items, prefix):
"""
If action groups are repeated, then links in the table of contents will
just go to the first of the repeats. This may not be desirable, particularly
Expand All @@ -234,6 +234,7 @@ def ensureUniqueIDs(items):
for n in item.traverse(descend=True, siblings=True, ascend=False):
if isinstance(n, nodes.section):
ids = n['ids']
ids = ['%s %s' % (prefix, i) for i in ids]
for idx, id in enumerate(ids):
if id not in s:
s.add(id)
Expand Down Expand Up @@ -416,24 +417,29 @@ def _nested_parse_paragraph(self, text):
return content

def run(self):
prefix = ''
if 'module' in self.options and 'func' in self.options:
module_name = self.options['module']
attr_name = self.options['func']
prefix = 'module-%s.%s' % (module_name, attr_name)
elif 'ref' in self.options:
_parts = self.options['ref'].split('.')
module_name = '.'.join(_parts[0:-1])
attr_name = _parts[-1]
prefix = 'module-%s.%s' % (module_name, attr_name)
elif 'filename' in self.options and 'func' in self.options:
filename = self.options['filename']
mod = {}
try:
f = open(self.options['filename'])
f = open(filename)
except IOError:
# try open with abspath
f = open(os.path.abspath(self.options['filename']))
code = compile(f.read(), self.options['filename'], 'exec')
f = open(os.path.abspath(filename))
code = compile(f.read(), filename, 'exec')
exec(code, mod)
attr_name = self.options['func']
func = mod[attr_name]
prefix = '%s.%s' % (filename, attr_name)
else:
raise self.error(
':module: and :func: should be specified, or :ref:, or :filename: and :func:')
Expand Down Expand Up @@ -503,7 +509,7 @@ def run(self):
items.append(self._nested_parse_paragraph(result['epilog']))

# Traverse the returned nodes, modifying the title IDs as necessary to avoid repeats
ensureUniqueIDs(items)
ensureUniqueIDs(items, prefix)

return items

Expand Down