def do_autodoc(app, objtype, name, options={}): doccls = app.registry.documenters[objtype] docoptions = process_documenter_options(doccls, app.config, options) bridge = DocumenterBridge(app.env, LoggingReporter(''), docoptions, 1) documenter = doccls(bridge, name) documenter.generate() return bridge.result
def do_autodoc(app, objtype, name, options=None): if options is None: options = {} app.env.temp_data.setdefault("docname", "index") # set dummy docname doccls = app.registry.documenters[objtype] docoptions = process_documenter_options(doccls, app.config, options) state = Mock() state.document.settings.tab_width = 8 bridge = DocumenterBridge(app.env, LoggingReporter(""), docoptions, 1, state) documenter = doccls(bridge, name) documenter.generate() return bridge.result
def run(self): reporter = self.state.document.reporter try: source, lineno = reporter.get_source_and_line(self.lineno) # type: ignore except AttributeError: source, lineno = (None, None) logger.debug('[sphinxcontrib-matlabdomain] %s:%s: input:\n%s', source, lineno, self.block_text) # look up target Documenter objtype = self.name.replace('auto', '') # Removes auto doccls = self.env.app.registry.documenters[objtype] # process the options with the selected documenter's option_spec try: documenter_options = process_documenter_options(doccls, self.config, self.options) except (KeyError, ValueError, TypeError) as exc: # an option is either unknown or has a wrong type logger.error('An option to %s is either unknown or has an invalid value: %s' % (self.name, exc), location=(source, lineno)) return [] # generate the output if version_info[0] >= 2: params = DocumenterBridge(self.env, reporter, documenter_options, lineno, self.state) else: params = DocumenterBridge(self.env, reporter, documenter_options, lineno) documenter = doccls(params, self.arguments[0]) documenter.generate(more_content=self.content) if not params.result: return [] logger.debug('[sphinxcontrib-matlabdomain] output:\n%s', '\n'.join(params.result)) # record all filenames as dependencies -- this will at least # partially make automatic invalidation possible for fn in params.filename_set: self.state.document.settings.record_dependencies.add(fn) result = parse_generated_content(self.state, params.result, documenter) return result
def run(self): reporter = self.state.document.reporter try: source, lineno = reporter.get_source_and_line(self.lineno) except AttributeError: source, lineno = (None, None) # look up target Documenter objtype = self.name[4:-4] # strip prefix (auto-) and suffix (-summ). doccls = self.env.app.registry.documenters[objtype] self.options['autosummary-force-inline'] = "True" self.options['autosummary'] = "True" if 'no-members' not in self.options: self.options['members'] = "" # process the options with the selected documenter's option_spec try: documenter_options = process_documenter_options(doccls, self.config, self.options) except (KeyError, ValueError, TypeError) as exc: # an option is either unknown or has a wrong type logger.error( 'An option to %s is either unknown or has an invalid ' 'value: %s', self.name, exc, location=(self.env.docname, lineno)) return [] # generate the output params = DocumenterBridge(self.env, reporter, documenter_options, lineno, self.state) documenter = doccls(params, self.arguments[0]) documenter.add_autosummary() node = nodes.paragraph() node.document = self.state.document self.state.nested_parse(params.result, 0, node) return node.children
def autosummary_documenter(self): """Returns the AutosummaryDocumenter subclass that can be used""" try: return self._autosummary_documenter except AttributeError: pass objtype = self.name[4:] env = self.state.document.settings.env if sphinx_version < [1, 7]: doc_class = self._registry[objtype] params = self else: reporter = self.state.document.reporter try: lineno = reporter.get_source_and_line(self.lineno)[1] except AttributeError: lineno = None doc_class = get_documenters(self.env.app)[objtype] args = (self.state, ) if sphinx_version >= [2, 1] else () params = DocumenterBridge( env, reporter, process_documenter_options(doc_class, env.config, self.options), lineno, *args) documenter = doc_class(params, self.arguments[0]) if hasattr(documenter, 'get_grouped_documenters'): self._autosummary_documenter = documenter return documenter # in case the has been changed in the registry, we decide manually if objtype == 'module': documenter = AutoSummModuleDocumenter(params, self.arguments[0]) elif objtype == 'class': documenter = AutoSummClassDocumenter(params, self.arguments[0]) else: raise ValueError( "Could not find a valid documenter for the object type %s" % ( objtype)) self._autosummary_documenter = documenter return documenter