Example #1
0
    def run(self):
        """Run method for the directive"""
        doc_nodes = AutoDirective.run(self)
        if 'autosummary' not in self.options:
            return doc_nodes
        self.warnings = []
        self.env = self.state.document.settings.env
        self.result = ViewList()
        documenter = self.autosummary_documenter
        grouped_documenters = documenter.get_grouped_documenters()
        if 'show-formatoptions' in self.env.config.autodoc_default_flags:
            self.options['show-formatoptions'] = True
        summ_nodes = self.autosumm_nodes(documenter, grouped_documenters)

        dn = summ_nodes.pop(documenter.fullname)
        doc_nodes = self.inject_summ_nodes(doc_nodes, summ_nodes)
        # insert the nodes directly after the paragraphs
        if self.name == 'autoclass':
            for node in dn[::-1]:
                self._insert_after_paragraphs(doc_nodes[1], node)
            dn = []
        elif self.name == 'automodule':
            # insert table before the documentation of the members
            istart = 2 if 'noindex' not in self.options else 0
            found = False
            if len(doc_nodes[istart:]) >= 2:
                for i in range(istart, len(doc_nodes)):
                    if isinstance(doc_nodes[i], sphinx.addnodes.index):
                        found = True
                        break
            if found:
                for node in dn[::-1]:
                    doc_nodes.insert(i, node)
                dn = []
        return self.warnings + dn + doc_nodes
Example #2
0
def generate_func_autodoc(app, func, add_title=True):
    ad = AutoDirective(
        name="autofunc",
        arguments=[FULL_NAMES[func]],
        options={"noindex": True},
        content=StringList([], items=[]),
        lineno=0,
        content_offset=1,
        block_text="",
        state=None,
        state_machine=None,
    )

    ad.env = BuildEnvironment(app)
    ad.genopt = Options(noindex=True)
    ad.filename_set = set()
    ad.result = ViewList()

    documenter = FunctionDocumenter(ad, ad.arguments[0])
    documenter.generate(all_members=True)

    title = 'Parameter Grids'
    with open(OUTPUT_FILES[func], "a") as fid:
        if add_title:
            fid.write(title + '\n')
            fid.write(''.join(['='] * len(title)) + '\n')
        for line in ad.result:
            fid.write(line + "\n")
Example #3
0
def generate_class_autodoc(app, cls):
    ad = AutoDirective(
        name="autoclass",
        arguments=[FULL_NAMES[cls]],
        options={"noindex": True},
        content=StringList([], items=[]),
        lineno=0,
        content_offset=1,
        block_text="",
        state=None,
        state_machine=None,
    )

    ad.env = BuildEnvironment(app)
    ad.genopt = Options(noindex=True)
    ad.filename_set = set()
    ad.result = ViewList()

    documenter = ClassDocumenter(ad, ad.arguments[0])
    documenter.generate(all_members=True)

    with open(OUTPUT_FILES[cls], "w") as fid:
        fid.write(cls + '\n')
        fid.write(''.join(['='] * len(cls)) + '\n')
        for line in ad.result:
            fid.write(line + "\n")
Example #4
0
    def run(self):
        self.load_agx_config()
        agx_defs = self.read_agx()
        ret = list()
        old_name = self.name
        self.name = 'autofunction'
        for transform in agx_defs:
            for generator in transform['generators']:
                sec = nodes.section()
                sec['ids'].append(generator['name'])
                text = "%s" % generator['name'].replace('.', ' - ')
                gen = nodes.subtitle(text=text)
                sec.append(gen)
                ret.append(sec)

                description = generator['description']
                if description:
                    desc = nodes.paragraph(text=description)
                    sec.append(desc)

                for handler in generator['handler']:
                    name = handler['name']
                    self.arguments = [handler['package_path']]
                    doc = AutoDirective.run(self)
                    sec += doc
                    body = doc[1].children[-1]
                    position = len(doc[1].children[-1]) - 2

                    dl = nodes.definition_list()
                    body.insert(position, dl)

                    iname = name[:name.find('.')]
                    dl.append(self._definition_item('Transform', iname))

                    iname = name[name.find('.') + 1:name.rfind('.')]
                    dl.append(self._definition_item('Generator', iname))

                    scope = handler['scope']
                    if scope is not None:
                        modulename = scope['class'].__module__
                        classname = scope['class'].__name__
                        iname = "%s.%s" % (modulename, classname)
                        dl.append(self._definition_item('Scope', iname))

                    iname = handler['order']
                    dl.append(self._definition_item('Order', iname))
        self.name = old_name
        return ret
Example #5
0
def generate_func_autodoc(app, func):
    ad = AutoDirective(name='autofunc',
                       arguments=[FULL_NAMES[func]],
                       options={'noindex': True},
                       content=StringList([], items=[]),
                       lineno=0,
                       content_offset=1,
                       block_text='',
                       state=None,
                       state_machine=None)

    ad.env = BuildEnvironment(app)
    ad.genopt = Options(noindex=True)
    ad.filename_set = set()
    ad.result = ViewList()

    documenter = FunctionDocumenter(ad, ad.arguments[0])
    documenter.generate(all_members=True)

    with open(OUTPUT_FILES[func], 'a') as fid:
        for line in ad.result:
            fid.write(line + '\n')