def run(self): env = self.state.document.settings.env app = env.app split_namespaces = 'split-namespaces' in self.options config_file = self.options.get('config-file') if config_file: app.info('loading config file %s' % config_file) conf = cfg.ConfigOpts() conf.register_opts(generator._generator_opts) conf( args=['--config-file', config_file], project='oslo.config.sphinxext', ) namespaces = conf.namespace[:] else: namespaces = [ c.strip() for c in self.content if c.strip() ] result = ViewList() source_name = '<' + __name__ + '>' for line in _format_option_help(app, namespaces, split_namespaces): result.append(line, source_name) node = nodes.section() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def run(self): size = self.options.get('size', 4) shuffle = 'shuffle' in self.options seed = self.options.get('seed', 42) titles = self.options.get('titles', False) width = self.options.get('width', None) env = self.state.document.settings.env app = env.app gallery_dir = app.builder.config.altair_gallery_dir gallery_ref = app.builder.config.altair_gallery_ref examples = populate_examples(shuffle=shuffle, shuffle_seed=seed, num_examples=size, gallery_dir=gallery_dir, gallery_ref=gallery_ref, code_below=True) include = MINIGALLERY_TEMPLATE.render(image_dir='/_images', gallery_dir=gallery_dir, examples=examples, titles=titles, width=width) # parse and return documentation result = ViewList() for line in include.split('\n'): result.append(line, "<altair-minigallery>") node = nodes.paragraph() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def run(self): path_to_model = self.arguments[0] np = os.path.normpath(os.path.join(os.getcwd(), path_to_model)) # check that the file exists if not os.path.isfile(np): raise IOError('File does not exist({0})'.format(np)) html_name = os.path.join(os.getcwd(), (os.path.basename(path_to_model).split('.')[0] + "_n2.html")) cmd = subprocess.Popen(['openmdao', 'view_model', np, '--no_browser', '--embed', '-o' + html_name]) cmd_out, cmd_err = cmd.communicate() rst = ViewList() # Add the content one line at a time. # Second argument is the filename to report in any warnings # or errors, third argument is the line number. env = self.state.document.settings.env docname = env.doc2path(env.docname) rst.append(".. raw:: html", docname, self.lineno) rst.append(" :file: %s" % html_name, docname, self.lineno) # Create a node. node = nodes.section() # Parse the rst. nested_parse_with_titles(self.state, rst, node) # And return the result. return node.children
def run(self): module_path, class_name, attribute_name = self.arguments mod = importlib.import_module(module_path) klass = getattr(mod, class_name) options = getattr(klass(), attribute_name) if not isinstance(options, OptionsDictionary): raise TypeError("Object '%s' is not an OptionsDictionary." % attribute_name) lines = ViewList() n = 0 for line in options.__rst__(): lines.append(line, "options table", n) n += 1 # Note applicable to System, Solver and Driver 'options', but not to 'recording_options' if attribute_name != 'recording_options': lines.append("", "options table", n+1) # Blank line required after table. # Create a node. node = nodes.section() node.document = self.state.document # Parse the rst. nested_parse_with_titles(self.state, lines, node) # And return the result. return node.children
def directive( dirname, arguments, options, content, lineno, content_offset, block_text, state, state_machine ): reverse_mapping = {} for name, func in mapping.items(): reverse_mapping.setdefault(func, []).append(name) filters = [] compare_ops = set(('lt', 'le', 'eq', 'ne', 'ge', 'gt')) for func, names in reverse_mapping.items(): aliases = sorted(names, key=len) aliases = sorted(aliases, key=lambda x: x in compare_ops) name = aliases.pop() filters.append((name, aliases, func)) filters.sort() result = ViewList() for name, aliases, func in filters: for item in format_function(name, aliases, func): result.append(item, '<jinjaext>') node = nodes.paragraph() state.nested_parse(result, content_offset, node) return node.children
def run(self): env = self.state.document.settings.env app = env.app namespace = " ".join(self.content).strip() app.info("documenting plugins from %r" % namespace) overline_style = self.options.get("overline-style", "") underline_style = self.options.get("underline-style", "=") def report_load_failure(mgr, ep, err): app.warn("Failed to load %s: %s" % (ep.module_name, err)) mgr = extension.ExtensionManager(namespace, on_load_failure_callback=report_load_failure) result = ViewList() if "detailed" in self.options: data = _detailed_list(mgr, over=overline_style, under=underline_style) else: data = _simple_list(mgr) for text, source in data: for line in text.splitlines(): result.append(line, source) # Parse what we have into a new section. node = nodes.section() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def run(self): env = self.state.document.settings.env app = env.app classname = self.arguments[0].split('(')[0].strip() try: obj = import_obj(classname, default_module='altair') except ImportError: raise warnings.warn('Could not make table for {0}. Unable to import' ''.format(object)) # create the table from the object include_vl_link = ('include-vegalite-link' in self.options) table = altair_rst_table(obj, include_description=include_vl_link) # parse and return documentation result = ViewList() for line in table: result.append(line, "<altair-class>") node = nodes.paragraph() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def run(self): namespace = ' '.join(self.content).strip() LOG.info('documenting plugins from %r' % namespace) overline_style = self.options.get('overline-style', '') underline_style = self.options.get('underline-style', '=') def report_load_failure(mgr, ep, err): LOG.warning(u'Failed to load %s: %s' % (ep.module_name, err)) mgr = extension.ExtensionManager( namespace, on_load_failure_callback=report_load_failure, ) result = ViewList() titlecase = 'titlecase' in self.options if 'detailed' in self.options: data = _detailed_list( mgr, over=overline_style, under=underline_style, titlecase=titlecase) else: data = _simple_list(mgr) for text, source in data: for line in text.splitlines(): result.append(line, source) # Parse what we have into a new section. node = nodes.section() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def run(self): # figure out what attributes to exclude: obj = import_obj_from_args(self.arguments) if not issubclass(obj, traitlets.HasTraits): raise ValueError('altair-class directive should only be used ' 'on altair classes; not {0}'.format(obj)) exclude = ['skip'] exclude.extend(getattr(obj, 'skip', [])) exclude.extend([attr for attr in obj.class_traits()]) exclude.extend([attr for attr in dir(traitlets.HasTraits) if not attr.startswith('_')]) # generate the documentation string rst_text = ALTAIR_CLASS_TEMPLATE.render( classname=self.arguments[0], exclude_members=','.join(exclude) ) # parse and return documentation result = ViewList() for line in rst_text.split("\n"): result.append(line, "<altair-class>") node = nodes.paragraph() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def run(self): """For each file in noseOfYeti/specs, output nodes to represent each spec file""" with hp.a_temp_file() as fle: fle.write(dedent(""" --- environments: { dev: {account_id: "123"} } stacks: { app: {} } """).encode('utf-8')) fle.seek(0) collector = Collector() collector.prepare(fle.name, {'bespin': {'extra': ""}, "command": None, "bash": None}) section = nodes.section() section['ids'].append("available-tasks") title = nodes.title() title += nodes.Text("Default tasks") section += title for name, task in sorted(collector.configuration['task_finder'].tasks.items(), key=lambda x: len(x[0])): lines = [name] + [" {0}".format(line.strip()) for line in task.description.split('\n')] viewlist = ViewList() for line in lines: viewlist.append(line, name) self.state.nested_parse(viewlist, self.content_offset, section) return [section]
class AutoFunction(ObjectDescription): def handle_signature(self, sig, signode): cache = _APP_CACHES.get(self.env.app, {}) key = CursorKind.FUNCTION_DECL, (sig, ) if key in cache: node, comment, start, end, _ = cache[key] result_type = node.type.get_result() signode += addnodes.desc_type(result_type.spelling, result_type.spelling + ' ') signode += addnodes.desc_name(node.spelling, node.spelling) paramlist = addnodes.desc_parameterlist() for argument in node.get_arguments(): parameter = addnodes.desc_parameter() parameter += addnodes.desc_type(argument.type.spelling, argument.type.spelling + ' ') parameter += nodes.Text(argument.spelling, argument.spelling) paramlist += parameter signode += paramlist self.content = ViewList() for lineno, line in enumerate(comment.splitlines(), start[0]): self.content.append(line, '<unknown>', lineno) return sig def get_index_text(self, name): return '%s (C function)' % name def add_target_and_index(self, name, sig, signode): CObject.add_target_and_index.__func__(self, name, sig, signode)
def append_class_hierarchy(node, state, cls, level=0, clstree=None): if clstree is None: clstree = [] name = normalize_class_name(cls.__module__, cls.__name__) clstree.append((level, name)) for c in cls.__bases__: if c != object: append_class_hierarchy(node, state, c, level+1, clstree) if level == 0: clstree = sorted(set(clstree), key=lambda x: -x[0]) depth = max(clstree, key=lambda x: x[0])[0] for level, name in [ (abs(level-depth), cls) for level, cls in clstree ]: row = hierarchy_row() row.level, row.depth = level, depth if level != depth: name = ':class:`%s`' % name list = ViewList() list.append(name, '') state.nested_parse(list, 0, row) node.append(row)
def _parse(self, rst_text, annotation): result = ViewList() for line in rst_text.split("\n"): result.append(line, annotation) node = nodes.paragraph() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def run(self): node = nodes.section() node.document = self.state.document result = ViewList() for line in self.make_rst(): result.append(line, '<autoroutr>') nested_parse_with_titles(self.state, result, node) return node.children
def run(self): node = nodes.section() node.document = self.state.document result = ViewList() for line in self.make_rst(): result.append(line, '<{0}>'.format(self.__class__.__name__)) nested_parse_with_titles(self.state, result, node) return node.children
def run(self): assert self.document_type in ["yaml", "json"] node = nodes.section() node.document = self.state.document result = ViewList() for line in self.make_rst(): result.append(line, "<rx>") nested_parse_with_titles(self.state, result, node) return node.children
def run(self): split_namespaces = 'split-namespaces' in self.options config_file = self.options.get('config-file') if config_file: LOG.info('loading config file %s', config_file) conf = cfg.ConfigOpts() conf.register_opts(generator._generator_opts) conf( args=['--config-file', config_file], project='oslo.config.sphinxext', ) namespaces = conf.namespace[:] else: namespaces = [ c.strip() for c in self.content if c.strip() ] result = ViewList() source_name = self.state.document.current_source with tempfile.NamedTemporaryFile(suffix='.rst', delete=False) as tmp: # NOTE(stephenfin): We dump the output to a tempfile to assist # people in debugging their broken config options. It would be good # to conditionalize this but that would require access to error # state from the directive, which we don't have, and would # necessitate holding the whole file, which could be rather large, # in memory while we wait on the decision. LOG.info('dumping output to %r', tmp.name) offset = 0 for count, line in enumerate(_format_option_help( namespaces, split_namespaces)): # FIXME(stephenfin): Some lines emitted are actually multiple # lines. This throws off our counter, which is rather annoying. # We handle this here but we should really handle it higher up. parts = line.split('\n') if len(parts) > 1: offset += len(parts) - 1 for part in parts: result.append(line, source_name, count + offset) tmp.write(line.encode('utf-8')) node = nodes.section() node.document = self.state.document # With the resolution for bug #1755783, we now parse the 'Opt.help' # attribute as rST. Unfortunately, there are a lot of broken option # descriptions out there and we don't want to break peoples' builds # suddenly. As a result, we disable 'warning-is-error' temporarily. # Users will still see the warnings but the build will continue. with logging.skip_warningiserror(): nested_parse_with_titles(self.state, result, node) return node.children
def run(self): viewlist = ViewList() for line in self.gen_rst(): print(line) viewlist.append(line, CL) node = nodes.section() node.document = self.state.document nested_parse_with_titles(self.state, viewlist, node) return node.children
def render(self, spec): viewlist = ViewList() for line in self.render_restructuredtext_markup(spec): viewlist.append(line, "<openapi>") node = nodes.section() node.document = self._state.document nested_parse_with_titles(self._state, viewlist, node) return node.children
def run(self): node = nodes.paragraph() node.document = self.state.document desc = ViewList() description = dedent(commands[self.arguments[0]].__doc__) for line in description.split('\n'): desc.append(line, "") self.state.nested_parse(desc, 0, node) return [node]
def run(self): # Construct an empty node new_content = ViewList() ref = u":ref:`{0} <{1}>`".format( self.options.get("label", "Link To"), "".join(self.arguments)) new_content.append(ref, source=self.content) self.content = new_content return super(LinkToBlock, self).run()
def make_example(dir): path = '../../examples/{0}/{0}'.format(dir) rst = ViewList() line_no = 0 for line in lines: line_no += 1 line = line.format(path).rstrip() rst.append(line, 'example.rst', line_no) return rst
def run(self): node = nodes.section() node.document = self.state.document result = ViewList() for line in self.make_rst(): result.append(line, "<autojinja>") nested_parse_with_titles(self.state, result, node) # result.pprint() return node.children
def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') state.nested_parse(vl, 0, node) row.append(nodes.entry('', node)) body.append(row)
def _parse_rst(state, rst_text): # Adapted from `autoprogram` source. result = ViewList() for line in rst_text.splitlines(): result.append(line, '<parsed>') node = nodes.section() node.document = state.document nested_parse_with_titles(state, result, node) return node
def run(self): node = nodes.section() node.document = self.state.document result = ViewList() for line in self.make_rst(): result.append(line, '<azhelpgen>') nested_parse_with_titles(self.state, result, node) return node.children
class Extractor(object): """ Main extraction class """ def __init__(self): """ """ self.content = ViewList("",'comment') self.lineno = 0 def extract(self, source): """ Process the source file and fill in the content. SOURCE is a fileobject. """ for l in source: self.lineno = self.lineno + 1 l = l.strip() m = re_comment.match(l) if m: self.comment(m.group(1), source) def comment(self, cur, source): """ Read the whole comment and strip the stars. CUR is currently read line and SOURCE is a fileobject with the source code. """ self.content.append(cur.strip(), "comment") for line in source: self.lineno = self.lineno + 1 line = line.strip() if re_cmtend.match(line): break if line.startswith("/*"): raise ExtractError("%d: Nested comments are not supported yet." % self.lineno) if line.startswith(".. "): self.content.append(line, "comment") continue m = re_cmtnext.match(line) if m: self.content.append(" " + m.group(1).strip(), "comment") continue self.content.append(line, "comment") self.content.append('\n', "comment")
def run(self): env = self.state.document.settings.env app = env.app spec_path = self.arguments[0] env.note_reread() dest_dir = join(dirname(self.state_machine.node.source), "gallery") if not exists (dest_dir): makedirs(dest_dir) target_id = "bokeh-plot-%d" % env.new_serialno('bokeh-plot') target_node = nodes.target('', '', ids=[target_id]) result = [target_node] source_position = self.options.get('source-position', 'below') spec = json.load(open(spec_path)) details = spec['details'] for i, detail in enumerate(details): path = detail['path'] name = detail['name'] prev_ref, next_ref = None, None if i > 0: prev_ref = "gallery_" + details[i-1]['name'] if i < len(details)-1: next_ref = "gallery_" + details[i+1]['name'] rst = DETAIL_TEMPLATE.render( name=name, underline="#"*len(name), path=abspath("../" + path), symbol=detail.get('symbol'), prev_ref=prev_ref, up_ref="gallery", next_ref=next_ref, source_position=source_position, ) with open(join(dest_dir, "%s.rst" % name), "w") as f: f.write(rst) env.clear_doc(join("docs", "gallery", name)) env.read_doc(join("docs", "gallery", name), app=app) result = ViewList() names = [detail['name'] for detail in details] env.gallery_names = [join("docs", "gallery", n) for n in names] text = GALLERY_TEMPLATE.render(names=names) for line in text.split("\n"): result.append(line, "<bokeh-gallery>") node = nodes.paragraph() node.document = self.state.document self.state.nested_parse(result, 0, node) return node.children
def run(self): lines = requests.get(self.arguments[0]).text.splitlines() content = ViewList() count = 0 for line in lines: content.append(line, None, count) count +=1 node = nodes.section() nested_parse_with_titles(self.state, content, node) return node.children
def parse(self, text): node = nodes.paragraph() vl = ViewList() for line in text.splitlines(): vl.append(line, '<xmlschema>') nested_parse_with_titles(self.state, vl, node) try: return node[0] except IndexError: return build_paragraph(text)
def run(self): result = ViewList() for line in _get_cogbin_data(): result.append(line, '<cogbin>') node = nodes.section() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def parse_text(directive, text, node_type=nodes.paragraph): """Parses text in ReST format and returns a node with the content.""" vl = ViewList() for line in text.split('\n'): vl.append(line, line) node = node_type(rawsource=text) directive.state.nested_parse(vl, 0, node) return node
def _parse_docstring(self, comment_text, line_number) -> nodes.paragraph: """ parse comment into a paragraph """ paragraph = nodes.paragraph() c = ViewList() for i, line in enumerate(comment_text.splitlines()): c.append(line, str(self.sourcepath), line_number + i) self.state.nested_parse(c, 0, paragraph) return paragraph
def run(self): env = self.state.document.settings.env app = env.app spec_path = self.arguments[0] env.note_reread() dest_dir = join(dirname(self.state_machine.node.source), "gallery") if not exists(dest_dir): makedirs(dest_dir) target_id = "bokeh-plot-%d" % env.new_serialno('bokeh-plot') target_node = nodes.target('', '', ids=[target_id]) result = [target_node] source_position = self.options.get('source-position', 'below') spec = json.load(open(spec_path)) details = spec['details'] for i, detail in enumerate(details): path = detail['path'] name = detail['name'] prev_ref, next_ref = None, None if i > 0: prev_ref = "gallery_" + details[i - 1]['name'] if i < len(details) - 1: next_ref = "gallery_" + details[i + 1]['name'] rst = DETAIL_TEMPLATE.render( name=name, underline="#" * len(name), path=abspath("../" + path), symbol=detail.get('symbol'), prev_ref=prev_ref, up_ref="gallery", next_ref=next_ref, source_position=source_position, ) with open(join(dest_dir, "%s.rst" % name), "w") as f: f.write(rst) env.clear_doc(join("docs", "gallery", name)) env.read_doc(join("docs", "gallery", name), app=app) result = ViewList() names = [detail['name'] for detail in details] env.gallery_names = [join("docs", "gallery", n) for n in names] text = GALLERY_TEMPLATE.render(names=names) for line in text.split("\n"): result.append(line, "<bokeh-gallery>") node = nodes.paragraph() node.document = self.state.document self.state.nested_parse(result, 0, node) return node.children
class AutoYAMLDirective(Directive): required_arguments = 1 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 parse_file(self, source): with open(source, 'r') as src: lines = src.read().splitlines() in_docstring = False for linenum, line in enumerate(lines, start=1): if line.startswith(self.config.autoyaml_doc_delimiter): in_docstring = True self._parse_line(line, source, linenum, True) elif line.startswith(self.config.autoyaml_comment) \ and in_docstring: self._parse_line(line, source, linenum) else: in_docstring = False # add terminating newline self._parse_line('', source, linenum) def _parse_line(self, line, source, linenum, starting=False): if starting: docstring = line[len(self.config.autoyaml_doc_delimiter):] else: docstring = line[len(self.config.autoyaml_comment):] # strip preceding whitespace if docstring and docstring[0] == ' ': docstring = docstring[1:] self.result.append(docstring, source, linenum)
def run(self) -> List[nodes.Node]: node = nodes.paragraph() node.document = self.state.document desc = ViewList() cmd = create_command(self.arguments[0]) assert cmd.__doc__ is not None description = dedent(cmd.__doc__) for line in description.split("\n"): desc.append(line, "") self.state.nested_parse(desc, 0, node) return [node]
def run(self): doc = ViewList() info = self.get_scenario_info() for request in info['requests']: self.write_request(doc, request['request']) doc.append('', '') self.write_response(doc, request['response']) doc.append('', '') return parse_rst(self.state, self.content_offset, doc)
def run(self): doc = ViewList() doc.append('', '') doc.append('.. class:: sentry-support-block', '') doc.append('', '') for item in self.content: doc.append(' ' + item, item) doc.append('', '') return parse_rst(self.state, self.content_offset, doc)
def jinja_changelog(dirname, arguments, options, content, lineno, content_offset, block_text, state, state_machine): doc = ViewList() changelog = file(os.path.join(os.path.dirname(jinja2.__file__), '..', 'CHANGES')) try: for line in islice(changelog, 3, None): doc.append(line.rstrip(), '<jinjaext>') finally: changelog.close() return parse_rst(state, content_offset, doc)
def make_field(self, directive): # treat content like docfields.Field value = directive.options.get(self.name) if value: name = nodes.field_name('', self.label) para = nodes.paragraph(rawsource=value) content = ViewList() content.append(value, *directive.content.items[0]) directive.state.nested_parse(content, directive.content_offset, para) body = nodes.field_body('', para) return nodes.field('', name, body)
def jinja_changelog(dirname, arguments, options, content, lineno, content_offset, block_text, state, state_machine): doc = ViewList() changelog = file( os.path.join(os.path.dirname(jinja2.__file__), '..', 'CHANGES')) try: for line in islice(changelog, 3, None): doc.append(line.rstrip(), '<jinjaext>') finally: changelog.close() return parse_rst(state, content_offset, doc)
def _parse_text(self, text): paragraph_node = paragraph() vl = ViewList() for idx, line in enumerate(text.split("\n")): vl.append(line, 'ext', idx) self.state.nested_parse(vl, 0, paragraph_node) return paragraph_node
def render_rst(d, rst): # convert restructured text in rst to nodes for output for directive "d" # this copied from sphinxcontrib.datatemplates # DataTemplateBase(rst.Directive) run method result = ViewList() data_source = d.env.docname for line in rst.splitlines(): result.append(line, data_source) node = nodes.section() node.document = d.state.document nested_parse_with_titles(d.state, result, node) return node.children
def _get_source_nodes(self, source): linenos = 'linenos' in self.options emphasize_lines = self.options.get('emphasize-lines', False) if emphasize_lines: linenos = True result = ViewList() text = SOURCE_TEMPLATE.render(source=source, linenos=linenos, emphasize_lines=emphasize_lines) for line in text.split("\n"): result.append(line, "<bokeh-plot>") node = nodes.paragraph() node.document = self.state.document self.state.nested_parse(result, 0, node) return node.children
def _nested_parse(state, text, node, with_titles=False): result = ViewList() if isinstance(text, str): for line in text.split("\n"): result.append(line, "<nested>") else: for line in text: result.append(line, "<nested>") if with_titles: _nested_parse_with_titles(state, result, node) else: state.nested_parse(result, 0, node)
def run(self): result = ViewList() source_name = '<' + __name__ + '>' for line in _format_option_help(config._OPTIONS): LOG.info(line) result.append(line, source_name) node = nodes.section() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def parse_text(directive, text, node_type=nodes.paragraph, where=None): """Parses text in ReST format and returns a node with the content.""" assert text is not None, "Missing text during parse_text in %s" % where vl = ViewList() for line in text.split("\n"): vl.append(line, line) node = node_type(rawsource=text) directive.state.nested_parse(vl, 0, node) return node
def run(self): pluginfinder = PluginFinder() node = nodes.section() node.document = self.state.document result = ViewList() for pluginmetadata in pluginfinder.get_plugins(): for line in pluginmetadata.generate(): result.append(line, "plugins") nested_parse_with_titles(self.state, result, node) return node.children
def parse_text(directive, text, node_type=nodes.paragraph, where=None): """Parses text in ReST format and returns a node with the content.""" assert text is not None, 'Missing text during parse_text in %s' % where vl = ViewList() for line in text.split('\n'): vl.append(line, line) node = node_type(rawsource=text) directive.state.nested_parse(vl, 0, node) return node
def make_httpdomain_rst(self, mapped_routes): node = nodes.section() node.document = self.state.document result = ViewList() routes = {} for route in mapped_routes: if route['method'] == ANY_KEY: method = 'any' else: method = route['method'] directives = http_directive( method, route['pattern'], route['docs'], ) routes[(method, route['pattern'])] = route for line in directives: result.append(line, '<autopyramid>') nested_parse_with_titles(self.state, result, node) for objnode in node.traverse(addnodes.desc): if objnode.get('domain') != 'http': continue for signode in objnode: if not isinstance(signode, addnodes.desc_signature): continue method = signode.get('method') path = signode.get('path') mapped_route = routes.get((method, path)) if not method or not path or not mapped_route: continue xref_node = self._make_view_source_xref(mapped_route) if not xref_node: continue xref_node += nodes.inline('', '[source]', classes=['viewcode-link']) source_node = addnodes.only(expr='html') source_node += xref_node signode += source_node return node.children
def run(self): env = self.state.document.settings.env app = env.app def info(msg): app.info('[reno] %s' % (msg,)) title = ' '.join(self.content) branch = self.options.get('branch') reporoot_opt = self.options.get('reporoot', '.') reporoot = os.path.abspath(reporoot_opt) relnotessubdir = self.options.get('relnotessubdir', defaults.RELEASE_NOTES_SUBDIR) notessubdir = self.options.get('notesdir', defaults.NOTES_SUBDIR) version_opt = self.options.get('version') # FIXME(dhellmann): Force this flag True for now and figure # out how Sphinx passes a "false" flag later. collapse = True # 'collapse-pre-releases' in self.options earliest_version = self.options.get('earliest-version') notesdir = os.path.join(relnotessubdir, notessubdir) info('scanning %s for %s release notes' % (os.path.join(reporoot, notesdir), branch or 'current branch')) ldr = loader.Loader( reporoot=reporoot, notesdir=notesdir, branch=branch, collapse_pre_releases=collapse, earliest_version=earliest_version, ) if version_opt is not None: versions = [ v.strip() for v in version_opt.split(',') ] else: versions = ldr.versions text = formatter.format_report( ldr, versions, title=title, ) source_name = '<' + __name__ + '>' result = ViewList() for line in text.splitlines(): result.append(line, source_name) node = nodes.section() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children
def run(self): env = self.state.document.settings.env app = env.app builder = app.builder # Some builders have no templates manager at all, and some # have the attribute set to None. templates = getattr(builder, 'templates', None) if not templates: LOG.warn('The builder has no template manager, ' 'ignoring the datatemplate directive.') return [] try: data_source = self.options['source'] except KeyError: error = self.state_machine.reporter.error( 'No source set for datatemplate directive', nodes.literal_block(self.block_text, self.block_text), line=self.lineno) return [error] try: template_name = self.options['template'] except KeyError: error = self.state_machine.reporter.error( 'No template set for datatemplate directive', nodes.literal_block(self.block_text, self.block_text), line=self.lineno) return [error] encoding = self.options.get('encoding', None) data = self._load_data(env, data_source, encoding) context = { 'make_list_table': helpers.make_list_table, 'make_list_table_from_mappings': helpers.make_list_table_from_mappings, 'data': data, } rendered_template = builder.templates.render( template_name, context, ) result = ViewList() for line in rendered_template.splitlines(): result.append(line, data_source) node = nodes.section() node.document = self.state.document nested_parse_with_titles(self.state, result, node) return node.children