From fff15f50f300f0b1a93ac90ccdfbcfa408846568 Mon Sep 17 00:00:00 2001 From: guido Date: Thu, 8 Feb 2007 15:52:49 +0100 Subject: [PATCH] [svn r38148] Made that stacks are built on seperate pages instead of inline in the function information, to avoid having > 5MB pages... --HG-- branch : trunk --- py/apigen/html.py | 14 +++---- py/apigen/htmlgen.py | 42 +++++++++++++-------- py/apigen/testing/test_apigen_functional.py | 5 +++ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/py/apigen/html.py b/py/apigen/html.py index be27fbcd9..1cb0953e0 100644 --- a/py/apigen/html.py +++ b/py/apigen/html.py @@ -160,15 +160,13 @@ class H(html): pass class CallStackDescription(Description): - def __init__(self, callstackdiv): - super(H.CallStackDescription, self).__init__( - H.Hideable('callsites', 'callsites', csdiv)) + pass - class CallStackItem(html.div): - def __init__(self, filename, lineno, traceback): - super(H.CallStackItem, self).__init__( - H.Hideable("stack trace %s - line %s" % (filename, lineno), - 'callstackitem', traceback)) + class CallStackLink(html.div): + def __init__(self, filename, lineno, href): + super(H.CallStackLink, self).__init__( + H.a("stack trace %s - line %s" % (filename, lineno), + href=href)) class Hideable(html.div): def __init__(self, name, class_, *content): diff --git a/py/apigen/htmlgen.py b/py/apigen/htmlgen.py index 262556c57..62a98f524 100644 --- a/py/apigen/htmlgen.py +++ b/py/apigen/htmlgen.py @@ -341,13 +341,9 @@ class ApiPageBuilder(AbstractPageBuilder): href = self.linker.get_lazyhref(sourcefile) csource = H.SourceSnippet(text, href, colored) - callstack = self.dsa.get_function_callpoints(dotted_name) - csitems = [] - for cs, _ in callstack: - csitems.append(self.build_callsite(dotted_name, cs)) + cslinks = self.build_callsites(dotted_name) snippet = H.FunctionDescription(localname, argdesc, docstring, - valuedesc, csource, csitems) - + valuedesc, csource, cslinks) return snippet def build_class_view(self, dotted_name): @@ -589,14 +585,30 @@ class ApiPageBuilder(AbstractPageBuilder): def is_in_pkg(self, sourcefile): return py.path.local(sourcefile).relto(self.projpath) - def build_callsite(self, functionname, call_site): - tbtag = self.gen_traceback(functionname, reversed(call_site)) - return H.CallStackItem(call_site[0].filename, call_site[0].lineno + 1, - tbtag) + def build_callsites(self, dotted_name): + callstack = self.dsa.get_function_callpoints(dotted_name) + cslinks = [] + for i, (cs, _) in enumerate(callstack): + link = self.build_callsite(dotted_name, cs, i) + cslinks.append(link) + return cslinks + + def build_callsite(self, dotted_name, call_site, index): + tbtag = self.gen_traceback(dotted_name, reversed(call_site)) + parent_dotted_name, _ = split_of_last_part(dotted_name) + nav = self.build_navigation(parent_dotted_name, False) + id = 'callsite_%s_%s' % (dotted_name, index) + reltargetpath = "api/%s.html" % (id,) + self.linker.set_link(id, reltargetpath) + href = self.linker.get_lazyhref(id) + self.write_page('call site %s for %s' % (index, dotted_name), + reltargetpath, tbtag, nav) + return H.CallStackLink(call_site[0].filename, call_site[0].lineno + 1, + href) _reg_source = py.std.re.compile(r'([^>]*)<(.*)>') - def gen_traceback(self, funcname, call_site): - tbdiv = H.div() + def gen_traceback(self, dotted_name, call_site): + tbtag = H.CallStackDescription() for frame in call_site: lineno = frame.lineno - frame.firstlineno source = frame.source @@ -631,7 +643,7 @@ class ApiPageBuilder(AbstractPageBuilder): else: sourcelink = H.div('source unknown (%s)' % (sourcefile,)) colored = mangled[:] - tbdiv.append(sourcelink) - tbdiv.append(H.div(*colored)) - return tbdiv + tbtag.append(sourcelink) + tbtag.append(H.div(*colored)) + return tbtag diff --git a/py/apigen/testing/test_apigen_functional.py b/py/apigen/testing/test_apigen_functional.py index 8362b582e..094c4a65c 100644 --- a/py/apigen/testing/test_apigen_functional.py +++ b/py/apigen/testing/test_apigen_functional.py @@ -100,6 +100,11 @@ def setup_fs_project(name): exec c in globals() assert pak.somenamespace._hidden() == 'quux' + + # this just to see a multi-level stack in the docs + def foo(): + return pak.main.sub.func(10) + assert foo() is None """)) return temp, 'pak'