[py-svn] r33074 - in py/branch/apigen/py: code test/tracer test/tracer/testing
fijal at codespeak.net
fijal at codespeak.net
Mon Oct 9 21:56:08 CEST 2006
Author: fijal
Date: Mon Oct 9 21:56:06 2006
New Revision: 33074
Modified:
py/branch/apigen/py/code/code.py
py/branch/apigen/py/test/tracer/description.py
py/branch/apigen/py/test/tracer/docstorage.py
py/branch/apigen/py/test/tracer/genrest.py
py/branch/apigen/py/test/tracer/testing/test_rest.py
Log:
Added some sorting-out-of-outcome.
Modified: py/branch/apigen/py/code/code.py
==============================================================================
--- py/branch/apigen/py/code/code.py (original)
+++ py/branch/apigen/py/code/code.py Mon Oct 9 21:56:06 2006
@@ -67,6 +67,11 @@
return py.code.Source(self.path.read(mode="rU"))
fullsource = property(fullsource, None, None,
"full source containing this code object")
+
+ def source(self):
+ # return source only for that part of code
+ import inspect
+ return py.code.Source(inspect.getsource(self.raw))
def getargs(self):
# handfull shortcut for getting args
Modified: py/branch/apigen/py/test/tracer/description.py
==============================================================================
--- py/branch/apigen/py/test/tracer/description.py (original)
+++ py/branch/apigen/py/test/tracer/description.py Mon Oct 9 21:56:06 2006
@@ -4,13 +4,13 @@
import types
class CallSite(object):
- def __init__(self, filename, lineno, source):
+ def __init__(self, filename, lineno, frame):
self.filename = filename
self.lineno = lineno
- self.source = source
+ self.frame = frame
def get_tuple(self):
- return self.filename, self.lineno, self.source
+ return self.filename, self.lineno, self.frame
class NonHashableObject(object):
def __init__(self, cls):
@@ -57,7 +57,7 @@
self.inputcells[cell_num] = model.unionof(cell, self.inputcells[cell_num])
def consider_call_site(self, frame):
- self.call_sites.append(CallSite(frame.code.raw.co_filename, frame.lineno+1, str(frame.statement)))
+ self.call_sites.append(CallSite(frame.code.raw.co_filename, frame.lineno+1, frame))
def consider_return(self, arg):
self.retval = model.unionof(arg, self.retval)
Modified: py/branch/apigen/py/test/tracer/docstorage.py
==============================================================================
--- py/branch/apigen/py/test/tracer/docstorage.py (original)
+++ py/branch/apigen/py/test/tracer/docstorage.py Mon Oct 9 21:56:06 2006
@@ -71,7 +71,7 @@
desc = ClassDesc(key, value)
for name in dir(value):
field = getattr(value, name)
- if name != '__init__' and isinstance(field, types.MethodType):
+ if isinstance(field, types.MethodType):
real_name = key + '.' + name
md = MethodDesc(real_name, field)
self.descs[real_name] = md
@@ -111,6 +111,12 @@
def get_function_doc(self, name):
return self.ds.descs[name].pyobj.__doc__ or "*Not documented*"
+ def get_function_definition(self, name):
+ desc = self.ds.descs[name]
+ assert isinstance(desc, FunctionDesc)
+ code = py.code.Code(desc.code)
+ return code.fullsource[code.firstlineno]
+
def get_function_args(self, name):
return self.ds.descs[name].inputcells
@@ -123,6 +129,11 @@
return self.ds.module.__name__
return "Unknown module"
+ def get_class_methods(self, name):
+ desc = self.ds.descs[name]
+ assert isinstance(desc, ClassDesc)
+ return desc.getfields()
+
#def get_object_info(self, key):
#
Modified: py/branch/apigen/py/test/tracer/genrest.py
==============================================================================
--- py/branch/apigen/py/test/tracer/genrest.py (original)
+++ py/branch/apigen/py/test/tracer/genrest.py Mon Oct 9 21:56:06 2006
@@ -5,6 +5,7 @@
import py
import sys
+import re
from py.__.test.tracer.docstorage import DocStorageAccessor
from py.__.rst.rst import * # XXX Maybe we should list it here
@@ -86,17 +87,70 @@
Paragraph(self.dsa.get_module_info()),
Title("Exported functions:", belowchar="-")]
self.write_function_list(lst)
+ lst.append(Title("Exported classes:", belowchar="-"))
self.write_class_list(lst)
self.writer.write_file(filename, Rest(*lst).text())
def write_function_list(self, lst):
for name in self.dsa.get_function_names():
# XXX: should be .html here?
- lst.append(ListItem(Text("Function: "), Link(name, "function_%s" % name)))
+ lst.append(ListItem(Text("Function: "), Link(name, "function_%s.html" % name)))
+ self.write_function('function_' + name + '.txt', name)
def write_class_list(self, lst):
for name in self.dsa.get_class_names():
- lst.append(ListItem(Text("Class: "), Link(name, "class_%s" % name)))
+ lst.append(ListItem(Text("Class: "), Link(name, "class_%s.html" % name)))
+ self.write_class('class_' + name + '.txt', name)
+
+ def write_class(self, filename, class_name):
+ lst = [Title("Class: %s" % class_name, belowchar='-')]
+
+ # write down exported methods
+ lst.append(Title("Exported methods:", belowchar="^"))
+ for method in self.dsa.get_class_methods(class_name):
+ fname = "method_%s" % (class_name + \
+ "_" + method)
+ lst.append(ListItem(Link(method, fname+'.html')))
+ self.write_function(fname+'.txt', class_name + "." + method)
+
+ self.writer.write_file(filename, Rest(*lst).text())
+
+ def write_function(self, filename, fun_name):
+ lst = [Title("Function: %s" % fun_name, belowchar="-"),
+ Paragraph(self.dsa.get_function_doc(fun_name)),
+ BlockQuote(self.dsa.get_function_definition(fun_name))]
+ args = self.dsa.get_function_args(fun_name)
+ arg_str = "(%s)" % (",".join([str(i) for i in args]))
+ arg_quote = Paragraph("Function type:", Quote(arg_str))
+ lst.append(arg_quote)
+
+ # call sites..
+ call_site_title = Title("Call sites:", belowchar="-")
+ lst.append(call_site_title)
+ call_sites = lst
+
+ for call_site in self.dsa.get_function_callpoints(fun_name):
+ link_str = "File %s:%s" % (call_site.filename,
+ call_site.lineno)
+ #_, 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(BlockQuote(call_site.source))
+ # XXX: For now, we just paste here the filename of that
+ call_sites.append(Paragraph(link_str))
+ source = call_site.frame.code.source()
+ lines = []
+ for num, line in enumerate(source):
+ if num == call_site.lineno - call_site.frame.code.firstlineno - 1:
+ m = re.match("^( *)(.*)", line)
+ lines.append(">" + "-"*len(m.group(1)) + m.group(2))
+ else:
+ lines.append(" " + line)
+ call_sites.append(BlockQuote("\n".join(lines)))
+
+ self.writer.write_file(filename, Rest(*lst).text())
##class RestGen(object):
## def __init__(self, ds, linkgen, output=sys.stdout):
## self.dsa = DocStorageAccessor(ds)
Modified: py/branch/apigen/py/test/tracer/testing/test_rest.py
==============================================================================
--- py/branch/apigen/py/test/tracer/testing/test_rest.py (original)
+++ py/branch/apigen/py/test/tracer/testing/test_rest.py Mon Oct 9 21:56:06 2006
@@ -42,7 +42,9 @@
class TestRest(object):
def check_rest(self, tmpdir):
- pass
+ from py.__.misc import rest
+ for path in tmpdir.listdir('*.txt'):
+ rest.process(path)
def test_generation_simple_api(self):
descs = {'SomeClass':SomeClass, 'fun':fun}
More information about the py-svn
mailing list