def run(self): """ The task runner for the rst processing :return: list of the document tree element nodes :rtype :list: `Docutils document tree element class node` :raise CloudformationYAMLException """ self.config = self.state.document.settings.env.config self.env = self.state.document.settings.env self.record_dependencies = \ self.state.document.settings.record_dependencies location = os.path.normpath( os.path.join( self.env.srcdir, self.config.cloudformationyaml_root + '/' + self.arguments[0])) self.result = ViewList() #check file exists # should probably walk the filesystem here if os.path.isfile(location): self.parse_file(location) else: raise CloudformationYAMLException( '%s:%s: location "%s" is not a file.' % (self.env.doc2path(self.env.docname, None), self.content_offset - 1, location)) self.record_dependencies.add(location) node = nodes.paragraph() # parse comment internals as reST old_reporter = self.state.memo.reporter self.state.memo.reporter = AutodocReporter(self.result, self.state.memo.reporter) nested_parse_with_titles(self.state, self.result, node) self.state.memo.reporter = old_reporter return [node]
def run(self): self.config = self.state.document.settings.env.config self.env = self.state.document.settings.env self.record_dependencies = \ self.state.document.settings.record_dependencies location = os.path.normpath( os.path.join(self.env.srcdir, self.config.autoyaml_root + '/' + self.arguments[0])) self.result = ViewList() if os.path.isfile(location): logger.debug('[autoyaml] parsing file: %s', location) self.parse_file(location) else: raise AutoYAMLException('%s:%s: location "%s" is not a file.' % (self.env.doc2path(self.env.docname, None), self.content_offset - 1, location)) self.record_dependencies.add(location) node = nodes.paragraph() # parse comment internals as reST old_reporter = self.state.memo.reporter self.state.memo.reporter = AutodocReporter(self.result, self.state.memo.reporter) nested_parse_with_titles(self.state, self.result, node) self.state.memo.reporter = old_reporter return [node]
def do_parse(self, rstlist, node): """Parse rST source lines and add them to the specified node Take the list of rST source lines rstlist, parse them as rST, and add the resulting docutils nodes as children of node. The nodes are parsed in a way that allows them to include subheadings (titles) without confusing the rendering of anything else. """ # This is from kerneldoc.py -- it works around an API change in # Sphinx between 1.6 and 1.7. Unlike kerneldoc.py, we use # sphinx.util.nodes.nested_parse_with_titles() rather than the # plain self.state.nested_parse(), and so we can drop the saving # of title_styles and section_level that kerneldoc.py does, # because nested_parse_with_titles() does that for us. if Use_SSI: with switch_source_input(self.state, rstlist): nested_parse_with_titles(self.state, rstlist, node) else: save = self.state.memo.reporter self.state.memo.reporter = AutodocReporter( rstlist, self.state.memo.reporter) try: nested_parse_with_titles(self.state, rstlist, node) finally: self.state.memo.reporter = save
def nestedParse(self, lines, fname): content = ViewList() node = nodes.section() if "debug" in self.options: code_block = "\n\n.. code-block:: rst\n :linenos:\n" for l in lines.split("\n"): code_block += "\n " + l lines = code_block + "\n\n" for c, l in enumerate(lines.split("\n")): content.append(l, fname, c) buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter if Use_SSI: with switch_source_input(self.state, content): self.state.nested_parse(content, 0, node, match_titles=1) else: self.state.memo.title_styles = [] self.state.memo.section_level = 0 self.state.memo.reporter = AutodocReporter(content, self.state.memo.reporter) try: self.state.nested_parse(content, 0, node, match_titles=1) finally: self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf return node.children
def do_parse(self, result, node): if Use_SSI: with switch_source_input(self.state, result): nested_parse_with_titles(self.state, result, node) else: save = self.state.memo.reporter self.state.memo.reporter = AutodocReporter(result, self.state.memo.reporter) try: nested_parse_with_titles(self.state, result, node) finally: self.state.memo.reporter = save
def do_parse(self, result, node): if Use_SSI: with switch_source_input(self.state, result): self.state.nested_parse(result, 0, node, match_titles=1) else: save = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter self.state.memo.reporter = AutodocReporter(result, self.state.memo.reporter) self.state.memo.title_styles, self.state.memo.section_level = [], 0 try: self.state.nested_parse(result, 0, node, match_titles=1) finally: self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = save
def do_parse(self, content, node): if Use_SSI: with switch_source_input(self.state, content): self.state.nested_parse(content, 0, node, match_titles=1) else: buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter self.state.memo.title_styles = [] self.state.memo.section_level = 0 self.state.memo.reporter = AutodocReporter( content, self.state.memo.reporter) try: self.state.nested_parse(content, 0, node, match_titles=1) finally: self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf
def run(self): env = self.state.document.settings.env filename = os.path.join(env.config.cdoc_srcdir, self.arguments[0]) env.note_dependency(os.path.abspath(filename)) ## create a (view) list from the extracted doc lst = docutils.statemachine.ViewList() f = open(filename, 'r') for (lineno, lines) in extract(f, filename): for l in lines.split('\n'): lst.append(l.expandtabs(8), filename, lineno) lineno += 1 ## let parse this new reST content memo = self.state.memo save = memo.reporter, memo.title_styles, memo.section_level memo.reporter = AutodocReporter(lst, memo.reporter) node = docutils.nodes.section() try: self.state.nested_parse(lst, 0, node, match_titles=1) finally: memo.reporter, memo.title_styles, memo.section_level = save return node.children
def run(self): env = self.state.document.settings.env cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno'] filename = env.config.kerneldoc_srctree + '/' + self.arguments[0] export_file_patterns = [] # Tell sphinx of the dependency env.note_dependency(os.path.abspath(filename)) tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) # FIXME: make this nicer and more robust against errors if 'export' in self.options: cmd += ['-export'] export_file_patterns = str(self.options.get('export')).split() elif 'internal' in self.options: cmd += ['-internal'] export_file_patterns = str(self.options.get('internal')).split() elif 'doc' in self.options: cmd += ['-function', str(self.options.get('doc'))] elif 'functions' in self.options: functions = self.options.get('functions').split() if functions: for f in functions: cmd += ['-function', f] else: cmd += ['-no-doc-sections'] for pattern in export_file_patterns: for f in glob.glob(env.config.kerneldoc_srctree + '/' + pattern): env.note_dependency(os.path.abspath(f)) cmd += ['-export-file', f] cmd += [filename] try: env.app.verbose('calling kernel-doc \'%s\'' % (" ".join(cmd))) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() out, err = codecs.decode(out, 'utf-8'), codecs.decode(err, 'utf-8') if p.returncode != 0: sys.stderr.write(err) env.app.warn('kernel-doc \'%s\' failed with return code %d' % (" ".join(cmd), p.returncode)) return [ nodes.error(None, nodes.paragraph(text="kernel-doc missing")) ] elif env.config.kerneldoc_verbosity > 0: sys.stderr.write(err) lines = statemachine.string2lines(out, tab_width, convert_whitespace=True) result = ViewList() lineoffset = 0 line_regex = re.compile("^#define LINENO ([0-9]+)$") for line in lines: match = line_regex.search(line) if match: # sphinx counts lines from 0 lineoffset = int(match.group(1)) - 1 # we must eat our comments since the upset the markup else: result.append(line, filename, lineoffset) lineoffset += 1 node = nodes.section() buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter self.state.memo.reporter = AutodocReporter( result, self.state.memo.reporter) self.state.memo.title_styles, self.state.memo.section_level = [], 0 try: self.state.nested_parse(result, 0, node, match_titles=1) finally: self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf return node.children except Exception as e: # pylint: disable=W0703 env.app.warn('kernel-doc \'%s\' processing failed with: %s' % (" ".join(cmd), str(e))) return [ nodes.error(None, nodes.paragraph(text="kernel-doc missing")) ]