diff --git a/py/apigen/apigen.py b/py/apigen/apigen.py index 3990236d4..a92386a86 100644 --- a/py/apigen/apigen.py +++ b/py/apigen/apigen.py @@ -15,7 +15,7 @@ from py.__.apigen.tracer.docstorage import pkg_to_dict def get_documentable_items(pkgdir): sys.path.insert(0, str(pkgdir.dirpath())) rootmod = __import__(pkgdir.basename) - return pkg_to_dict(rootmod) + return 'py', pkg_to_dict(rootmod) def build(pkgdir, dsa): l = linker.Linker() diff --git a/py/apigen/testing/test_apigen_functional.py b/py/apigen/testing/test_apigen_functional.py index 12efe459a..3b48c9402 100644 --- a/py/apigen/testing/test_apigen_functional.py +++ b/py/apigen/testing/test_apigen_functional.py @@ -82,7 +82,9 @@ def setup_fs_project(name): def test_get_documentable_items(): fs_root, package_name = setup_fs_project('test_get_documentable_items') - documentable = apigen.get_documentable_items(fs_root.join(package_name)) + pkgname, documentable = apigen.get_documentable_items( + fs_root.join(package_name)) + assert pkgname == 'py' assert sorted(documentable.keys()) == [ 'main.SomeTestClass', 'main.SomeTestSubClass', 'main.func', 'main.sub.func', 'somenamespace.baz', 'somenamespace.foo'] diff --git a/py/apigen/tracer/docstorage.py b/py/apigen/tracer/docstorage.py index 194bf1b7a..0b2b6bc61 100644 --- a/py/apigen/tracer/docstorage.py +++ b/py/apigen/tracer/docstorage.py @@ -56,6 +56,9 @@ def get_star_import_tree(module, modname): class DocStorage(object): """ Class storing info about API """ + def __init__(self): + self.module_name = None + def consider_call(self, frame, caller_frame, upward_cut_frame=None): assert isinstance(frame, py.code.Frame) desc = self.find_desc(frame.code, frame.raw.f_locals) @@ -102,7 +105,8 @@ class DocStorage(object): for key, desc in self.descs.iteritems(): self.desc_cache[desc] = desc - def from_dict(self, _dict, keep_frames = False): + def from_dict(self, _dict, keep_frames=False, module_name=None): + self.module_name = module_name self.descs = {} for key, val in _dict.iteritems(): to_key, to_val = self.make_desc(key, val) @@ -155,7 +159,7 @@ class DocStorage(object): def from_pkg(self, module, keep_frames=False): self.module = module - self.from_dict(pkg_to_dict(module), keep_frames) + self.from_dict(pkg_to_dict(module), keep_frames, module.__name__) # XXX return self @@ -260,7 +264,9 @@ class DocStorageAccessor(AbstractDocStorageAccessor): return sorted([i.__name__ for i in self.ds.descs[name].exceptions.keys()]) def get_module_name(self): - if hasattr(self.ds, 'module'): + if self.ds.module_name is not None: + return self.ds.module_name + elif hasattr(self.ds, 'module'): return self.ds.module.__name__ return "Unknown module" diff --git a/py/test/rsession/rsession.py b/py/test/rsession/rsession.py index 31c5da74b..e373a9b7b 100644 --- a/py/test/rsession/rsession.py +++ b/py/test/rsession/rsession.py @@ -270,32 +270,14 @@ class LSession(AbstractSession): def init_runner(self): if self.config.option.apigen: from py.__.apigen.tracer.tracer import Tracer, DocStorage - module = py - try: - pkgdir = self.getpkgdir(self.config.args[0]) - apigen = py.path.local(self.config.option.apigen).pyimport() - items = apigen.get_documentable_items(pkgdir) - if isinstance(items, dict): - self.docstorage = DocStorage().from_dict(items) - else: - self.docstorage = DocStorage().from_pkg(items) - except ImportError: - import traceback - exc, e, tb = sys.exc_info() - print '%s - %s' % (exc, e) - print ''.join(traceback.format_tb(tb)) - del tb - print '-' * 79 - raise ImportError("Provided script cannot be imported") - except (ValueError, AttributeError): - import traceback - exc, e, tb = sys.exc_info() - print '%s - %s' % (exc, e) - print ''.join(traceback.format_tb(tb)) - del tb - print '-' * 79 + pkgdir = self.getpkgdir(self.config.args[0]) + apigen = py.path.local(self.config.option.apigen).pyimport() + if not hasattr(apigen, 'get_documentable_items'): raise NotImplementedError("Provided script does not seem " "to contain get_documentable_items") + pkgname, items = apigen.get_documentable_items(pkgdir) + self.docstorage = DocStorage().from_dict(items, + module_name=pkgname) self.tracer = Tracer(self.docstorage) return apigen_runner else: