def inheritance_diagram_directive(name, arguments, options, content, lineno,
                                  content_offset, block_text, state,
                                  state_machine):
    """
    Run when the inheritance_diagram directive is first encountered.
    """
    node = inheritance_diagram()

    class_names = arguments

    # Create a graph starting with the list of classes
    graph = InheritanceGraph(class_names)

    # Create xref nodes for each target of the graph's image map and
    # add them to the doc tree so that Sphinx can resolve the
    # references to real URLs later.  These nodes will eventually be
    # removed from the doctree after we're done with them.
    for name in graph.get_all_class_names():
        refnodes, x = xfileref_role('class', ':class:`%s`' % name, name, 0,
                                    state)
        node.extend(refnodes)
    # Store the graph object so we can use it to generate the
    # dot file later
    node['graph'] = graph
    # Store the original content for use as a hash
    node['parts'] = options.get('parts', 0)
    node['content'] = " ".join(class_names)
    return [node]
Beispiel #2
0
def autolink_role(typ,
                  rawtext,
                  etext,
                  lineno,
                  inliner,
                  options={},
                  content=[]):
    """
    Smart linking role.

    Expands to ':obj:`text`' if `text` is an object that can be imported;
    otherwise expands to '*text*'.
    """
    r = roles.xfileref_role('obj', rawtext, etext, lineno, inliner, options,
                            content)
    pnode = r[0][0]

    prefixes = [None]
    #prefixes.insert(0, inliner.document.settings.env.currmodule)
    try:
        obj, name = import_by_name(pnode['reftarget'], prefixes)
    except ImportError:
        content = pnode[0]
        r[0][0] = nodes.emphasis(rawtext,
                                 content[0].astext(),
                                 classes=content['classes'])
    return r
def inheritance_diagram_directive(name, arguments, options, content, lineno,
                                  content_offset, block_text, state,
                                  state_machine):
    """
    Run when the inheritance_diagram directive is first encountered.
    """
    node = inheritance_diagram()

    class_names = arguments

    # Create a graph starting with the list of classes
    graph = InheritanceGraph(class_names)

    # Create xref nodes for each target of the graph's image map and
    # add them to the doc tree so that Sphinx can resolve the
    # references to real URLs later.  These nodes will eventually be
    # removed from the doctree after we're done with them.
    for name in graph.get_all_class_names():
        refnodes, x = xfileref_role(
            'class', ':class:`%s`' % name, name, 0, state)
        node.extend(refnodes)
    # Store the graph object so we can use it to generate the
    # dot file later
    node['graph'] = graph
    # Store the original content for use as a hash
    node['parts'] = options.get('parts', 0)
    node['content'] = " ".join(class_names)
    return [node]
Beispiel #4
0
 def run(self):
     env = self.state.document.settings.env
     arg0 = self.arguments[0]
     is_nextversion = env.config.django_next_version == arg0
     ret = []
     node = addnodes.versionmodified()
     ret.append(node)
     if not is_nextversion:
         if len(self.arguments) == 1:
             linktext = 'Please, see the release notes <releases-%s>' % \
                        (arg0,)
             try:
                 # Sphinx >= 1.0
                 xrefs = roles.XRefRole()('std:ref', linktext, linktext,
                                          self.lineno, self.state)
             except AttributeError:
                 # Sphinx < 1.0
                 xrefs = roles.xfileref_role('ref', linktext, linktext,
                                             self.lineno, self.state)
             node.extend(xrefs[0])
         node['version'] = arg0
     else:
         node['version'] = "Development version"
     node['type'] = self.name
     if len(self.arguments) == 2:
         inodes, messages = self.state.inline_text(self.arguments[1],
                                                   self.lineno + 1)
         node.extend(inodes)
         if self.content:
             self.state.nested_parse(self.content, self.content_offset,
                                     node)
         ret = ret + messages
     env.note_versionchange(node['type'], node['version'], node,
                            self.lineno)
     return ret
Beispiel #5
0
def parse_version_directive(name, arguments, options, content, lineno,
                      content_offset, block_text, state, state_machine):
    env = state.document.settings.env
    is_nextversion = env.config.django_next_version == arguments[0]
    ret = []
    node = addnodes.versionmodified()
    ret.append(node)
    if not is_nextversion:
        if len(arguments) == 1:
            linktext = 'Please, see the release notes <releases-%s>' % (arguments[0])
            try:
                xrefs = roles.XRefRole()('ref', linktext, linktext, lineno, state) # Sphinx >= 1.0
            except:
                xrefs = roles.xfileref_role('ref', linktext, linktext, lineno, state) # Sphinx < 1.0
            node.extend(xrefs[0])
        node['version'] = arguments[0]
    else:
        node['version'] = "Development version"
    node['type'] = name
    if len(arguments) == 2:
        inodes, messages = state.inline_text(arguments[1], lineno+1)
        node.extend(inodes)
        if content:
            state.nested_parse(content, content_offset, node)
        ret = ret + messages
    env.note_versionchange(node['type'], node['version'], node, lineno)
    return ret
Beispiel #6
0
 def run(self):
     env = self.state.document.settings.env
     arg0 = self.arguments[0]
     is_nextversion = env.config.django_next_version == arg0
     ret = []
     node = addnodes.versionmodified()
     ret.append(node)
     if not is_nextversion:
         if len(self.arguments) == 1:
             linktext = 'Please, see the release notes </releases/%s>' % (arg0)
             try:
                 xrefs = roles.XRefRole()('doc', linktext, linktext, self.lineno, self.state) # Sphinx >= 1.0
             except AttributeError:
                 xrefs = roles.xfileref_role('doc', linktext, linktext, self.lineno, self.state) # Sphinx < 1.0
             node.extend(xrefs[0])
         node['version'] = arg0
     else:
         node['version'] = "Development version"
     node['type'] = self.name
     if len(self.arguments) == 2:
         inodes, messages = self.state.inline_text(self.arguments[1], self.lineno+1)
         node.extend(inodes)
         if self.content:
             self.state.nested_parse(self.content, self.content_offset, node)
         ret = ret + messages
     env.note_versionchange(node['type'], node['version'], node, self.lineno)
     return ret
Beispiel #7
0
def parse_version_directive(name, arguments, options, content, lineno,
                            content_offset, block_text, state, state_machine):
    env = state.document.settings.env
    is_nextversion = env.config.django_next_version == arguments[0]
    ret = []
    node = addnodes.versionmodified()
    ret.append(node)
    if not is_nextversion:
        if len(arguments) == 1:
            linktext = 'Please, see the release notes <releases-%s>' % (
                arguments[0])
            try:
                xrefs = roles.XRefRole()('ref', linktext, linktext, lineno,
                                         state)  # Sphinx >= 1.0
            except:
                xrefs = roles.xfileref_role('ref', linktext, linktext, lineno,
                                            state)  # Sphinx < 1.0
            node.extend(xrefs[0])
        node['version'] = arguments[0]
    else:
        node['version'] = "Development version"
    node['type'] = name
    if len(arguments) == 2:
        inodes, messages = state.inline_text(arguments[1], lineno + 1)
        node.extend(inodes)
        if content:
            state.nested_parse(content, content_offset, node)
        ret = ret + messages
    env.note_versionchange(node['type'], node['version'], node, lineno)
    return ret
Beispiel #8
0
def inheritance_diagram_directive(name, arguments, options, content, lineno,
                                  content_offset, block_text, state,
                                  state_machine):
    """
    Run when the inheritance_diagram directive is first encountered.
    """
    node = inheritance_diagram()
    class_names = arguments
    graph = InheritanceGraph(class_names)
    for name in graph.get_all_class_names():
        refnodes, x = xfileref_role(
            'class', ':class:`%s`' % name, name, 0, state)
        node.extend(refnodes)
    node['graph'] = graph
    node['parts'] = options.get('parts', 0)
    node['content'] = " ".join(class_names)
    return [node]
class InheritanceDiagram(Directive):
    """
    Run when the inheritance_diagram directive is first encountered.
    """
    has_content = False
    required_arguments = 1
    optional_arguments = 0
    final_argument_whitespace = True
    option_spec = {
        'parts': directives.nonnegative_int,
    }

    def run(self):
        node = inheritance_diagram()
        node.document = self.state.document
        env = self.state.document.settings.env
        class_names = self.arguments[0].split()

        # Create a graph starting with the list of classes
        try:
            graph = InheritanceGraph(class_names, env.currmodule)
        except InheritanceException, err:
            return [
                node.document.reporter.warning(err.args[0], line=self.lineno)
            ]

        # Create xref nodes for each target of the graph's image map and
        # add them to the doc tree so that Sphinx can resolve the
        # references to real URLs later.  These nodes will eventually be
        # removed from the doctree after we're done with them.
        for name in graph.get_all_class_names():
            refnodes, x = xfileref_role('class', ':class:`%s`' % name, name, 0,
                                        self.state)
            node.extend(refnodes)
        # Store the graph object so we can use it to generate the
        # dot file later
        node['graph'] = graph
        # Store the original content for use as a hash
        node['parts'] = self.options.get('parts', 0)
        node['content'] = ', '.join(class_names)
        return [node]
Beispiel #10
0
def autolink_role(typ, rawtext, etext, lineno, inliner,
                  options={}, content=[]):
    """
    Smart linking role.

    Expands to ':obj:`text`' if `text` is an object that can be imported;
    otherwise expands to '*text*'.
    """
    r = roles.xfileref_role('obj', rawtext, etext, lineno, inliner,
                            options, content)
    pnode = r[0][0]

    prefixes = [None]
    #prefixes.insert(0, inliner.document.settings.env.currmodule)
    try:
        obj, name = import_by_name(pnode['reftarget'], prefixes)
    except ImportError:
        content = pnode[0]
        r[0][0] = nodes.emphasis(rawtext, content[0].astext(),
                                 classes=content['classes'])
    return r