[Epydoc-commits] SF.net SVN: epydoc: [1748] trunk/epydoc/src/epydoc
Brought to you by:
edloper
From: <ed...@us...> - 2008-02-23 06:59:21
|
Revision: 1748 http://epydoc.svn.sourceforge.net/epydoc/?rev=1748&view=rev Author: edloper Date: 2008-02-22 22:59:20 -0800 (Fri, 22 Feb 2008) Log Message: ----------- - Added dotgraph support to epytext's latex output - Added dotgraph support to rst's latex output - DotGrah.to_latex() now writes both the .eps and the .pdf file (no language switch) - Fixed bug in dotgraph when context=None - Fixed bug in dotgraph in call to mk_valdoc_node - Fixed bug in epytext in graph raising Modified Paths: -------------- trunk/epydoc/src/epydoc/docwriter/dotgraph.py trunk/epydoc/src/epydoc/docwriter/latex.py trunk/epydoc/src/epydoc/markup/epytext.py trunk/epydoc/src/epydoc/markup/restructuredtext.py Modified: trunk/epydoc/src/epydoc/docwriter/dotgraph.py =================================================================== --- trunk/epydoc/src/epydoc/docwriter/dotgraph.py 2008-02-23 06:01:41 UTC (rev 1747) +++ trunk/epydoc/src/epydoc/docwriter/dotgraph.py 2008-02-23 06:59:20 UTC (rev 1748) @@ -130,25 +130,26 @@ self.uid = '%s_%s' % (self.uid, n) self._uids.add(self.uid) - def to_latex(self, image_file, language='ps', center=True): - # Write the image file. - if language == 'ps': - self.write(image_file, language='ps') - elif language == 'pdf': - ps = self._run_dot('-Tps') - psfilename = tempfile.mktemp('.ps') - psfile = open(psfilename, 'wb') - psfile.write('%!PS-Adobe-2.0 EPSF-1.2\n') - psfile.write(ps) - psfile.close() - try: run_subprocess(('ps2pdf', '-dEPSCrop', psfilename, - image_file)) - except RunSubprocessError, e: - log.warning("Unable to render Graphviz dot graph (%s):\n" + def to_latex(self, image_file, center=True): + """ + Return the LaTeX code that should be used to display this + graph. Two image files will be written: image_file+'.eps' + and image_file+'.pdf'. + """ + # Render the graph in postscript. + ps = self._run_dot('-Tps') + # Write the postscript output. + psfile = open(image_file+'.eps', 'wb') + psfile.write('%!PS-Adobe-2.0 EPSF-1.2\n') + psfile.write(ps) + psfile.close() + # Use ps2pdf to generate the pdf output. + try: run_subprocess(('ps2pdf', '-dEPSCrop', image_file+'.eps', + image_file+'.pdf')) + except RunSubprocessError, e: + log.warning("Unable to render Graphviz dot graph (%s):\n" "ps2pdf failed." % self.title) - return None - else: - raise ValueError('Expected language to be "ps" or "pdf"') + return None # Generate the latex code to display the graph. name = os.path.splitext(os.path.split(image_file)[-1])[0] @@ -811,7 +812,8 @@ def _get_html_label(self): # Get the class name & contextualize it. classname = self.class_doc.canonical_name - classname = classname.contextualize(self.context.canonical_name) + if context is not None: + classname = classname.contextualize(self.context.canonical_name) # If we're collapsed, display the node as a single box. if self.collapsed: @@ -1414,12 +1416,14 @@ """ nodes = {} for val_doc in sorted(val_docs, key=lambda d:d.canonical_name): - nodes[val_doc] = mk_valdoc_node(graph, val_doc, linker, context) + nodes[val_doc] = mk_valdoc_node(val_doc, linker, context) graph.nodes.append(nodes[val_doc]) return nodes def mk_valdoc_node(val_doc, linker, context): - label = val_doc.canonical_name.contextualize(context.canonical_name) + label = val_doc.canonical_name + if context is not None: + label = label.contextualize(context.canonical_name) node = DotGraphNode(label) specialize_valdoc_node(node, val_doc, context, linker.url_for(val_doc)) return node @@ -1488,12 +1492,13 @@ node['style'] = 'filled,bold' def name_list(api_docs, context=None): + names = [d.canonical_name for d in api_docs] if context is not None: - context = context.canonical_name - names = [str(d.canonical_name.contextualize(context)) for d in api_docs] + names = [name.contextualize(context.canonical_name) for name in names] if len(names) == 0: return '' if len(names) == 1: return '%s' % names[0] elif len(names) == 2: return '%s and %s' % (names[0], names[1]) else: + names = ['%s' % name for name in names] return '%s, and %s' % (', '.join(names[:-1]), names[-1]) Modified: trunk/epydoc/src/epydoc/docwriter/latex.py =================================================================== --- trunk/epydoc/src/epydoc/docwriter/latex.py 2008-02-23 06:01:41 UTC (rev 1747) +++ trunk/epydoc/src/epydoc/docwriter/latex.py 2008-02-23 06:59:20 UTC (rev 1748) @@ -359,14 +359,9 @@ def render_graph(self, graph): if graph is None: return '' graph.caption = graph.title = None - if self._pdflatex: - image_url = '%s.pdf' % graph.uid - image_file = os.path.join(self._directory, image_url) - return graph.to_latex(image_file, 'pdf') or '' - else: - image_url = '%s.eps' % graph.uid - image_file = os.path.join(self._directory, image_url) - return graph.to_latex(image_file, 'ps') or '' + image_url = '%s' % graph.uid + image_file = os.path.join(self._directory, image_url) + return graph.to_latex(image_file) or '' def write_class(self, out, doc): if self._list_classes_separately: @@ -1095,6 +1090,8 @@ def docstring_to_latex(self, docstring, indent=0, breakany=0): if docstring is None: return '' s = docstring.to_latex(self._docstring_linker, indent=indent, + directory=self._directory, + docindex=self.docindex, hyperref=self._hyperref) return (' '*indent + '\\begin{EpydocDescription}%\n' + s.strip() + '%\n' + Modified: trunk/epydoc/src/epydoc/markup/epytext.py =================================================================== --- trunk/epydoc/src/epydoc/markup/epytext.py 2008-02-23 06:01:41 UTC (rev 1747) +++ trunk/epydoc/src/epydoc/markup/epytext.py 2008-02-23 06:59:20 UTC (rev 1748) @@ -345,10 +345,10 @@ block = ('section', 'fieldlist', 'field', 'ulist', 'olist', 'li') if have_graph_child and tree.tag not in block: child_index = 0 + parent_index = parent.children.index(tree) for elt in tree.children: if isinstance(elt, Element) and elt.tag == 'graph': # We found a graph: splice it into the parent. - parent_index = parent.children.index(tree) left = tree.children[:child_index] right = tree.children[child_index+1:] parent.children[parent_index:parent_index+1] = [ @@ -357,6 +357,7 @@ Element(tree.tag, *right, **tree.attribs)] child_index = 0 parent_index += 2 + tree = parent.children[parent_index] else: child_index += 1 @@ -1782,12 +1783,14 @@ docindex, context, indent) return self._html - def to_latex(self, docstring_linker, **options): + def to_latex(self, docstring_linker, directory=None, docindex=None, + context=None, **options): if self._latex is not None: return self._latex if self._tree is None: return '' indent = options.get('indent', 0) self._hyperref = options.get('hyperref', 1) - self._latex = self._to_latex(self._tree, docstring_linker, indent) + self._latex = self._to_latex(self._tree, docstring_linker, directory, + docindex, context, indent) return self._latex def to_plaintext(self, docstring_linker, **options): @@ -1873,6 +1876,7 @@ symbol = tree.children[0] return self.SYMBOL_TO_HTML.get(symbol, '[%s]' % symbol) elif tree.tag == 'graph': + if directory is None: return '' # Generate the graph. graph = self._build_graph(variables[0], variables[1:], linker, docindex, context) @@ -1931,8 +1935,8 @@ else: log.warning("Unknown graph type %s" % graph_type) - - def _to_latex(self, tree, linker, indent=0, seclevel=0, breakany=0): + def _to_latex(self, tree, linker, directory, docindex, context, + indent=0, seclevel=0, breakany=0): if isinstance(tree, basestring): return plaintext_to_latex(tree, breakany=breakany) @@ -1941,7 +1945,8 @@ # Figure out the child indent level. if tree.tag == 'epytext': cindent = indent else: cindent = indent + 2 - variables = [self._to_latex(c, linker, cindent, seclevel, breakany) + variables = [self._to_latex(c, linker, directory, docindex, + context, cindent, seclevel, breakany) for c in tree.children] childstr = ''.join(variables) @@ -2002,8 +2007,14 @@ symbol = tree.children[0] return self.SYMBOL_TO_LATEX.get(symbol, '[%s]' % symbol) elif tree.tag == 'graph': - return '(GRAPH)' - #raise ValueError, 'graph not implemented yet for latex' + if directory is None: return '' + # Generate the graph. + graph = self._build_graph(variables[0], variables[1:], linker, + docindex, context) + if not graph: return '' + # Write the graph. + image_file = os.path.join(directory, graph.uid) + return graph.to_latex(image_file) else: # Assume that anything else can be passed through. return childstr Modified: trunk/epydoc/src/epydoc/markup/restructuredtext.py =================================================================== --- trunk/epydoc/src/epydoc/markup/restructuredtext.py 2008-02-23 06:01:41 UTC (rev 1747) +++ trunk/epydoc/src/epydoc/markup/restructuredtext.py 2008-02-23 06:59:20 UTC (rev 1748) @@ -198,9 +198,11 @@ self._document.walkabout(visitor) return ''.join(visitor.body) - def to_latex(self, docstring_linker, **options): + def to_latex(self, docstring_linker, directory=None, + docindex=None, context=None, **options): # Inherit docs - visitor = _EpydocLaTeXTranslator(self._document, docstring_linker) + visitor = _EpydocLaTeXTranslator(self._document, docstring_linker, + directory, docindex, context) self._document.walkabout(visitor) return ''.join(visitor.body).strip()+'\n' @@ -537,14 +539,15 @@ def latex_head_prefix(): document = new_document('<fake>') - translator = _EpydocLaTeXTranslator(document, None) + translator = _EpydocLaTeXTranslator(document) return translator.head_prefix _TARGET_RE = re.compile(r'^(.*?)\s*<(?:URI:|URL:)?([^<>]+)>$') class _EpydocLaTeXTranslator(LaTeXTranslator): settings = None - def __init__(self, document, docstring_linker): + def __init__(self, document, docstring_linker=None, directory=None, + docindex=None, context=None): # Set the document's settings. if self.settings is None: settings = OptionParser([LaTeXWriter()]).get_default_values() @@ -554,6 +557,9 @@ LaTeXTranslator.__init__(self, document) self._linker = docstring_linker + self._directory = directory + self._docindex = docindex + self._context = context # Start at section level 3. (Unfortunately, we now have to # set a private variable to make this work; perhaps the standard @@ -574,12 +580,18 @@ def visit_document(self, node): pass def depart_document(self, node): pass - # For now, just ignore dotgraphs. [XXX] def visit_dotgraph(self, node): - log.warning("Ignoring dotgraph in latex output (dotgraph " - "rendering for latex not implemented yet).") + if self._directory is None: raise SkipNode() # [xx] warning? + + # Generate the graph. + graph = node.graph(self._docindex, self._context, self._linker) + if graph is None: raise SkipNode() + + # Write the graph. + image_file = os.path.join(self._directory, graph.uid) + self.body.append(graph.to_latex(image_file)) raise SkipNode() - + def visit_doctest_block(self, node): self.body.append(doctest_to_latex(node[0].astext())) raise SkipNode() @@ -672,11 +684,11 @@ **attributes) def visit_dotgraph(self, node): - if self._directory is None: return # [xx] warning? + if self._directory is None: raise SkipNode() # [xx] warning? # Generate the graph. graph = node.graph(self._docindex, self._context, self._linker) - if graph is None: return + if graph is None: raise SkipNode() # Write the graph. image_url = '%s.gif' % graph.uid This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |