[py-svn] r33942 - py/dist/py/apigen/rest

guido at codespeak.net guido at codespeak.net
Tue Oct 31 12:08:27 CET 2006


Author: guido
Date: Tue Oct 31 12:08:26 2006
New Revision: 33942

Modified:
   py/dist/py/apigen/rest/genrest.py
Log:
Some cleanups, getting rid of passing the ReST lists around, and of writing 
sections while walking through the trees (so now the traceback sections are
written _after_ tree walking, just like the other sections), added first bits
of a real traceback page (but not yet full ;).


Modified: py/dist/py/apigen/rest/genrest.py
==============================================================================
--- py/dist/py/apigen/rest/genrest.py	(original)
+++ py/dist/py/apigen/rest/genrest.py	Tue Oct 31 12:08:26 2006
@@ -145,12 +145,19 @@
             for cname, crest, cfunclist in classlist:
                 self.writer.write_section('class_%s' % (cname,),
                                           Rest(*crest).text())
-                for fname, frest in cfunclist:
+                for fname, frest, tbdata in cfunclist:
+                    print 'frest:', frest
                     self.writer.write_section('method_%s' % (fname,),
                                               Rest(*frest).text())
-            for fname, frest in funclist:
+                    for tbname, tbrest in tbdata:
+                        self.writer.write_section('traceback_%s' % (tbname,),
+                                                  Rest(*tbrest).text())
+            for fname, frest, tbdata in funclist:
                 self.writer.write_section('function_%s' % (fname,),
                                           Rest(*frest).text())
+                for tbname, tbrest in tbdata:
+                    self.writer.write_section('traceback_%s' % (tbname,),
+                                              Rest(*tbrest).text())
     
     def build_classrest(self, classlist):
         classrest = self.build_classes(classlist)
@@ -163,9 +170,12 @@
 
     def build_funcrest(self, funclist):
         funcrest = self.build_functions(funclist)
-        for fname, rest in funcrest:
+        for fname, rest, tbdata in funcrest:
             self.writer.write_section('function_%s' % (fname,),
                                       Rest(*rest).text())
+            for tbname, tbrest in tbdata:
+                self.writer.write_section('traceback_%s' % (tbname,),
+                                          Rest(*tbrest).text())
 
     def build_index(self, modules):
         rest = [Title('Index', abovechar='=', belowchar='=')]
@@ -227,8 +237,8 @@
         for function in functions:
             if parent:
                 function = '%s.%s' % (parent, function)
-            rest = self.write_function(function, ismethod=methods)
-            ret.append((function, rest))
+            rest, tbrest = self.write_function(function, ismethod=methods)
+            ret.append((function, rest, tbrest))
         return ret
 
     def get_module_list(self):
@@ -288,6 +298,7 @@
         lst.append(Link(str(_type), _desc_type + "_" + name + ".html"))
 
     def write_function(self, functionname, ismethod=False, belowchar='-'):
+        print 'function', functionname
         # XXX I think the docstring should either be split on \n\n and cleaned
         # from indentation, or treated as ReST too (although this is obviously
         # dangerous for non-ReST docstrings)...
@@ -318,17 +329,6 @@
             if next:
                 items.append(Text(next))
             lst.append(ListItem(*items))
-            #if link:
-            #    link_str, link_target = link
-            #    lst.append(ListItem(Quote("%s :: %s" % (name, pre_str)), 
-            #        Link(link_str, link_target), Quote(post_str)))
-            #else:
-            #    lst.append(ListItem(Quote("%s :: %s%s" % (name, _type))))
-        
-        #arg_str = "\n".join(["%s :: %s" % (str(name), str(type))
-        #                     for name, type in args])
-        #arg_str += "\n" + "Return value :: %s" % str(retval)
-        #lst.append(LiteralBlock(arg_str))
         
         # XXX missing implementation of dsa.get_function_location()
         #filename, lineno = self.dsa.get_function_location(functionname)
@@ -340,12 +340,6 @@
         lst.append(Paragraph('Function source:'))
         lst.append(LiteralBlock(self.dsa.get_function_source(functionname)))
         
-        #arg_str = "(%s)" % (",".join([str(i) for i in args]))
-        #ret_str = str(retval)
-        #arg_quote = Paragraph("Function type:", Quote(arg_str), '->',
-        #                      Quote(ret_str))
-        #lst.append(arg_quote)
-        
         # call sites..
         call_site_title = Title("Call sites:", belowchar='+')
         lst.append(call_site_title)
@@ -354,45 +348,30 @@
         # 1. A quick'n'dirty statement where call has appeared first (topmost)
         # 2. Link to short traceback
         # 3. Link to long traceback
+        tbrest = []
         for call_site, _ in self.dsa.get_function_callpoints(functionname):
-            self.write_call_site_link(call_site, lst)
-##        for call_site, frame in self.dsa.get_function_callpoints(functionname):
-##            link_str = "File %s:%s" % (call_site.filename,
-##                                       call_site.lineno)
-##            link_str, link_target = self.linkgen.getlink(call_site.filename,
-##                                                         call_site.lineno)
-##            if link_target: # otherwise it's just inline text
-##                call_sites.append(Paragraph(Link(link_str, link_target)))
-##            else:
-##                call_sites.append(Paragraph(link_str))
-##            #call_sites.append(LiteralBlock(call_site.source))
-##            # XXX: For now, we just paste here the filename of that
-##            #call_sites.append(Paragraph(link_str))
-##            try:
-##                source = frame.code.source()
-##            except KeyboardInterrupt, SystemError:
-##                raise
-##            except:
-##                source = "*Cannot get source*"
-##            lines = []
-##            for num, line in enumerate(source):
-##                if num == call_site.lineno - frame.code.firstlineno - 1:
-##                    m = re.match("^( *)(.*)", line)
-##                    lines.append(">%s%s" % ("-" * len(m.group(1)), m.group(2)))
-##                else:
-##                    lines.append(" " + line)
-##            call_sites.append(LiteralBlock("\n".join(lines)))
-        
-        return lst
-
-    def write_call_site_link(self, call_site, lst):
-        name = self.gen_traceback(call_site)
-        lst.append(Paragraph("Called in %s" % call_site[0].code.filename, Link\
-            ("Full %s" % name, name + '.html')))
+            fdata, tbdata = self.call_site_link(functionname, call_site)
+            lst += fdata
+            tbrest.append(tbdata)
+        
+        return lst, tbrest
+
+    def call_site_link(self, functionname, call_site):
+        tbid, tbrest = self.gen_traceback(call_site)
+        tbname = '%s.%s' % (functionname, tbid)
+        linktarget = self.writer.getlink('traceback',
+                                         tbname,
+                                         'traceback_%s' % (tbname,))
+        frest = [Paragraph("Called in %s" % call_site[0].code.filename),
+                 Paragraph(Link("Full traceback %s" % (tbname,),
+                 linktarget))]
+        return frest, (tbname, tbrest)
     
     def gen_traceback(self, call_site):
-        name = "traceback_%d" % self.traceback_no
+        tbid = self.traceback_no
         self.traceback_no += 1
-        print name
-        self.writer.write_section(name, Rest(*[Title("Random traceback here")]).text())
-        return name
+        tbrest = [Title('Full traceback')]
+        for line in call_site:
+            tbrest.append(ListItem('%4s: %s' % (line.lineno + 1,
+                line.code.source()[line.lineno - line.code.firstlineno])))
+        return tbid, tbrest



More information about the pytest-commit mailing list