def run(self): node = graphviz() dotted = self.arguments[0].split()[0] # Get the workflow for ``dotted``. try: workflow = Workflow(dotted) except WorkflowException as err: return [node.document.reporter.warning( err.args[0], line=self.lineno)] node['code'] = workflow.generate_dot(self.name) node['options'] = {} if 'graphviz_dot' in self.options: node['options']['graphviz_dot'] = self.options['graphviz_dot'] if 'alt' in self.options: node['alt'] = self.options['alt'] if 'inline' in self.options: node['inline'] = True caption = self.options.get('caption') if caption: node = figure_wrapper(self, node, caption) return [node]
def run(self): if self.arguments: # Read code from file document = self.state.document if self.content: return [document.reporter.warning( __('wavedrom directive cannot have both content and ' 'a filename argument'), line=self.lineno)] argument = search_image_for_language(self.arguments[0], self.env) rel_filename, filename = self.env.relfn2path(argument) self.env.note_dependency(rel_filename) try: with open(filename, 'r') as fp: # type: ignore code = fp.read() except (IOError, OSError): return [document.reporter.warning( __('External wavedrom json file %r not found or reading ' 'it failed') % filename, line=self.lineno)] else: # Read code from given content code = "\n".join(self.content) if not code.strip(): return [self.state_machine.reporter.warning( __('Ignoring "wavedrom" directive without content.'), line=self.lineno)] # For html output with inline JS enabled, just return plain HTML if (self.env.app.builder.name in ('html', 'dirhtml', 'singlehtml') and self.config.wavedrom_html_jsinline): text = WAVEDROM_HTML.format(content=code) content = nodes.raw(text=text, format='html') return [content] # Store code in a special docutils node and pick up at rendering node = wavedromnode() node['code'] = code wd_node = node # point to the actual wavedrom node # A caption option turns this image into a Figure caption = self.options.get('caption') if caption: node = figure_wrapper(self, wd_node, caption) self.add_name(node) # Run image directive processing for the options, supply dummy argument, otherwise will fail. # We don't actually replace this node by the image_node and will also not make it a child, # because intermediate steps, like converters, depend on the file being in sources. We don't # want to generate any files in the user sources. Store the image_node private to this node # and not in the docutils tree and use it later. Revisit this when the situation changes. self.arguments = ["dummy"] (wd_node['image_node'],) = Image.run(self) return [node]
def run(self): env = self.state.document.settings.env node = traceable_graph() node["source"] = env.docname node["line"] = self.lineno node["traceables-tags"] = self.options["tags"] node["traceables-relationships"] = self.options.get("relationships") caption = self.options.get("caption") or "Traceable graph" node["traceables-caption"] = caption figure_node = graphviz.figure_wrapper(self, node, caption) return [figure_node]
def run(self): # type: () -> List[nodes.Node] node = inheritance_diagram() node.document = self.state.document class_names = self.arguments[0].split() class_role = self.env.get_domain('py').role('class') # Store the original content for use as a hash node['parts'] = self.options.get('parts', 0) node['content'] = ', '.join(class_names) node['top-classes'] = [] for cls in self.options.get('top-classes', '').split(','): cls = cls.strip() if cls: node['top-classes'].append(cls) # Create a graph starting with the list of classes try: graph = InheritanceGraph(class_names, self.env.ref_context.get('py:module'), parts=node['parts'], private_bases='private-bases' in self.options, aliases=self.config.inheritance_alias, top_classes=node['top-classes']) except InheritanceException as 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 = class_role( # type: ignore '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 if 'caption' not in self.options: self.add_name(node) return [node] else: figure = figure_wrapper(self, node, self.options['caption']) self.add_name(figure) return [figure]
def run(self) -> List[Node]: node = inheritance_diagram() node.document = self.state.document class_names = self.arguments[0].split() class_role = self.env.get_domain("py").role("class") # Store the original content for use as a hash node["parts"] = self.options.get("parts", 0) node["content"] = ", ".join(class_names) node["top-classes"] = [] for cls in self.options.get("top-classes", "").split(","): cls = cls.strip() if cls: node["top-classes"].append(cls) # Create a graph starting with the list of classes try: graph = InheritanceGraph( class_names, self.env.ref_context.get("py:module"), parts=node["parts"], private_bases="private-bases" in self.options, aliases=self.config.inheritance_alias, top_classes=node["top-classes"], ) except InheritanceException as err: return [node.document.reporter.warning(err, 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 = class_role( # type: ignore "class", ":class:`%s`" % name, name, 0, self.state) # type: ignore node.extend(refnodes) # Store the graph object so we can use it to generate the # dot file later node["graph"] = graph if "caption" not in self.options: self.add_name(node) return [node] else: figure = figure_wrapper(self, node, self.options["caption"]) self.add_name(figure) return [figure]
def run(self): # type: () -> List[nodes.Node] node = inheritance_diagram() node.document = self.state.document class_names = self.arguments[0].split() class_role = self.env.get_domain('py').role('class') # Store the original content for use as a hash node['parts'] = self.options.get('parts', 0) node['content'] = ', '.join(class_names) node['top-classes'] = [] for cls in self.options.get('top-classes', '').split(','): cls = cls.strip() if cls: node['top-classes'].append(cls) # Create a graph starting with the list of classes try: graph = InheritanceGraph( class_names, self.env.ref_context.get('py:module'), parts=node['parts'], private_bases='private-bases' in self.options, aliases=self.config.inheritance_alias, top_classes=node['top-classes']) except InheritanceException as 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 = class_role( # type: ignore '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 if 'caption' not in self.options: self.add_name(node) return [node] else: figure = figure_wrapper(self, node, self.options['caption']) self.add_name(figure) return [figure]
def run(self) -> List[Node]: node = wavedrom() node["code"] = "\n".join(self.content) node["options"] = {"docname": self.env.docname} if "alt" in self.options: node["alt"] = self.options["alt"] if "align" in self.options: node["align"] = self.options["align"] if "class" in self.options: node["classes"] = self.options["class"] if "caption" not in self.options: self.add_name(node) return [node] else: figure = figure_wrapper(self, node, self.options["caption"]) self.add_name(figure) return [figure]
def run(self): node = inheritance_diagram() node.document = self.state.document env = self.state.document.settings.env class_names = self.arguments[0].split() class_role = env.get_domain('py').role('class') # Store the original content for use as a hash node['parts'] = self.options.get('parts', 0) node['content'] = ', '.join(class_names) # Create a graph starting with the list of classes try: graph = InheritanceGraph(class_names, env.ref_context.get('py:module'), parts=node['parts'], private_bases='private-bases' in self.options) except InheritanceException as 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 = class_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 # wrap the result in figure node caption = self.options.get('caption') if caption: node = figure_wrapper(self, node, caption) return [node]
def run(self): node = inheritance_diagram() node.document = self.state.document env = self.state.document.settings.env class_names = self.arguments[0].split() class_role = env.get_domain('py').role('class') # Store the original content for use as a hash node['parts'] = self.options.get('parts', 0) node['content'] = ', '.join(class_names) # Create a graph starting with the list of classes try: graph = InheritanceGraph( class_names, env.ref_context.get('py:module'), parts=node['parts'], private_bases='private-bases' in self.options) except InheritanceException as 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 = class_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 # wrap the result in figure node caption = self.options.get('caption') if caption: node = figure_wrapper(self, node, caption) return [node]
def run(self) -> List[Node]: document = self.state.document source: str = "\n".join(self.content) filename: Optional[str] = None diagram_type: Optional[str] = None output_format: Optional[str] = None for argument in self.arguments: if argument in types: diagram_type = argument elif argument in formats: output_format = argument else: filename = argument if "filename" in self.options: if filename is not None: return [ document.reporter.warning( __("Kroki directive cannot have both filename option and " "a filename argument"), line=self.lineno, ) ] filename = self.options["filename"] if source.strip() and filename is not None: return [ document.reporter.warning( __("Kroki directive cannot have both content and " "a filename argument"), line=self.lineno, ) ] if filename is not None: argument = search_image_for_language(filename, self.env) rel_filename, filename = self.env.relfn2path(argument) self.env.note_dependency(rel_filename) try: with open(filename, encoding="utf-8") as fp: source = fp.read() except OSError: return [ document.reporter.warning( __("External kroki file %r not found or reading " "it failed") % filename, line=self.lineno, ) ] if not source.strip(): return [ document.reporter.warning( __("Ignoring kroki directive without content. It is necessary to specify " "filename argument/option or content"), line=self.lineno, ) ] if "type" in self.options: if diagram_type is not None: return [ document.reporter.warning( __("Kroki directive cannot have both type option and " "a type argument"), line=self.lineno, ) ] diagram_type = self.options["type"] if diagram_type is None: if filename is not None: diagram_type = extension_type_map.get( path.splitext(filename)[1]) if diagram_type is None: return [ document.reporter.warning( __("Kroki directive has to define diagram type."), line=self.lineno, ) ] if "format" in self.options: if output_format is not None: return [ document.reporter.warning( __("Kroki directive cannot have both format option and " "a format argument"), line=self.lineno, ) ] output_format = self.options["format"] node = kroki() node["type"] = diagram_type if output_format is not None: node["format"] = output_format node["code"] = source node["options"] = {"docname": self.env.docname} if "align" in self.options: node["align"] = self.options["align"] if "class" in self.options: node["classes"] = self.options["class"] if "caption" not in self.options: self.add_name(node) return [node] else: figure = figure_wrapper(self, node, self.options["caption"]) self.add_name(figure) return [figure]
def run(self): func_name = self.content[0] base_name = func_name.split(".")[0] if len(func_name.split(".")) == 1: func_name = None base_path = __import__(base_name).__path__[0] direction = "vertical" if "direction" in self.options: direction = self.options["direction"] dotcode = create_callgraph( filenames=f"{base_path}/**/*.py", function=func_name, namespace=base_name, format="dot", grouped="no-groups" not in self.options, draw_uses="no-uses" not in self.options, draw_defines="no-defines" not in self.options, nested_groups="nested-groups" in self.options, colored="no-colors" not in self.options, annotated="annotated" in self.options, rankdir={ "horizontal": "LR", "vertical": "TB" }[direction], ) node = graphviz() # insert link targets into groups: first insert link, then reformat link if "toctree" in self.options: path = self.options["toctree"].strip("/") # create raw link dotcode = re.sub( r'([\w\d]+)(\s.+), (style="filled")', r'\1\2, href="../' + path + r'/\1.html", target="_blank", \3', dotcode, ) def create_link(dot_name): raw_link = re.sub(r"__(\w)", r".\1", dot_name) # determine if name this is a class by checking if its first letter is capital # (heuristic but should work almost always) splits = raw_link.rsplit(".", 2) if len(splits) > 1 and splits[-2][0].capitalize( ) == splits[-2][0]: # is class link = ".".join(splits[:-1]) + ".html#" + raw_link + '"' else: link = raw_link + '.html"' return link dotcode = re.sub( r'(href="../' + path + r'/)(\w+)(\.html")', lambda m: m.groups()[0] + create_link(m.groups()[1]), dotcode, ) node["code"] = dotcode node["options"] = {"docname": self.env.docname} if "graphviz_dot" in self.options: node["options"]["graphviz_dot"] = self.options["graphviz_dot"] if "layout" in self.options: node["options"]["graphviz_dot"] = self.options["layout"] if "alt" in self.options: node["alt"] = self.options["alt"] if "align" in self.options: node["align"] = self.options["align"] if "class" in self.options: classes = self.options["class"] else: classes = [] if "zoomable" in self.options: if len(classes) == 0: classes = ["zoomable-callgraph"] else: classes.append("zoomable-callgraph") if len(classes) > 0: node["classes"] = classes if "caption" not in self.options: self.add_name(node) return [node] else: figure = figure_wrapper(self, node, self.options["caption"]) self.add_name(figure) return [figure]
def run(self): if self.arguments: # Read code from file document = self.state.document if self.content: return [ document.reporter.warning(__( 'wavedrom directive cannot have both content and ' 'a filename argument'), line=self.lineno) ] argument = search_image_for_language(self.arguments[0], self.env) rel_filename, filename = self.env.relfn2path(argument) self.env.note_dependency(rel_filename) try: with open(filename, 'r') as fp: # type: ignore code = fp.read() except (IOError, OSError): return [ document.reporter.warning(__( 'External wavedrom json file %r not found or reading ' 'it failed') % filename, line=self.lineno) ] else: # Read code from given content code = "\n".join(self.content) if not code.strip(): return [ self.state_machine.reporter.warning( __('Ignoring "wavedrom" directive without content.'), line=self.lineno) ] # For html output with inline JS enabled, just return plain HTML if (self.env.app.builder.name in ('html', 'dirhtml', 'singlehtml') and self.config.wavedrom_html_jsinline): text = WAVEDROM_HTML.format(content=code) content = nodes.raw(text=text, format='html') return [content] # Store code in a special docutils node and pick up at rendering node = wavedromnode() node['code'] = code wd_node = node # point to the actual wavedrom node # A caption option turns this image into a Figure caption = self.options.get('caption') if caption: node = figure_wrapper(self, wd_node, caption) self.add_name(node) # Run image directive processing for the options, supply dummy argument, otherwise will fail. # We don't actually replace this node by the image_node and will also not make it a child, # because intermediate steps, like converters, depend on the file being in sources. We don't # want to generate any files in the user sources. Store the image_node private to this node # and not in the docutils tree and use it later. Revisit this when the situation changes. self.arguments = ["dummy"] (wd_node['image_node'], ) = Image.run(self) return [node]