[svn r38183] Made that py.execnet.Channel (referring to py.__.execnet.channel.Channel) is

picked up by the apigen doc generator, fixed some bugs that made that that
didn't work previously.

--HG--
branch : trunk
This commit is contained in:
guido 2007-02-08 18:28:55 +01:00
parent e89d5e5880
commit 1c1df46a55
4 changed files with 16 additions and 9 deletions

View File

@ -29,7 +29,7 @@ def get_documentable_items_pkgdir(pkgdir):
def get_documentable_items(pkgdir): def get_documentable_items(pkgdir):
pkgname, pkgdict = get_documentable_items_pkgdir(pkgdir) pkgname, pkgdict = get_documentable_items_pkgdir(pkgdir)
from py.__.execnet.channel import Channel from py.__.execnet.channel import Channel
# pkgdict['execnet.Channel'] = Channel # XXX doesn't work pkgdict['execnet.Channel'] = Channel
return pkgname, pkgdict return pkgname, pkgdict
def build(pkgdir, dsa, capture): def build(pkgdir, dsa, capture):

View File

@ -136,7 +136,7 @@ def enumerate_and_color(codelines, firstlineno, enc):
break break
return snippet return snippet
def get_obj(pkg, dotted_name): def get_obj(dsa, pkg, dotted_name):
full_dotted_name = '%s.%s' % (pkg.__name__, dotted_name) full_dotted_name = '%s.%s' % (pkg.__name__, dotted_name)
if dotted_name == '': if dotted_name == '':
return pkg return pkg
@ -146,8 +146,11 @@ def get_obj(pkg, dotted_name):
marker = [] marker = []
ret = getattr(ret, item, marker) ret = getattr(ret, item, marker)
if ret is marker: if ret is marker:
raise NameError('can not access %s in %s' % (item, try:
full_dotted_name)) return dsa.get_obj(dotted_name)
except KeyError:
raise NameError('can not access %s in %s' % (item,
full_dotted_name))
return ret return ret
# the PageBuilder classes take care of producing the docs (using the stuff # the PageBuilder classes take care of producing the docs (using the stuff
@ -314,7 +317,7 @@ class ApiPageBuilder(AbstractPageBuilder):
def build_callable_view(self, dotted_name): def build_callable_view(self, dotted_name):
""" build the html for a class method """ """ build the html for a class method """
# XXX we may want to have seperate # XXX we may want to have seperate
func = get_obj(self.pkg, dotted_name) func = get_obj(self.dsa, self.pkg, dotted_name)
docstring = func.__doc__ docstring = func.__doc__
if docstring: if docstring:
docstring = deindent(docstring) docstring = deindent(docstring)
@ -348,7 +351,7 @@ class ApiPageBuilder(AbstractPageBuilder):
def build_class_view(self, dotted_name): def build_class_view(self, dotted_name):
""" build the html for a class """ """ build the html for a class """
cls = get_obj(self.pkg, dotted_name) cls = get_obj(self.dsa, self.pkg, dotted_name)
# XXX is this a safe check? # XXX is this a safe check?
try: try:
sourcefile = inspect.getsourcefile(cls) sourcefile = inspect.getsourcefile(cls)
@ -419,7 +422,7 @@ class ApiPageBuilder(AbstractPageBuilder):
def build_namespace_view(self, namespace_dotted_name, item_dotted_names): def build_namespace_view(self, namespace_dotted_name, item_dotted_names):
""" build the html for a namespace (module) """ """ build the html for a namespace (module) """
obj = get_obj(self.pkg, namespace_dotted_name) obj = get_obj(self.dsa, self.pkg, namespace_dotted_name)
docstring = obj.__doc__ docstring = obj.__doc__
snippet = H.NamespaceDescription( snippet = H.NamespaceDescription(
H.NamespaceDef(namespace_dotted_name), H.NamespaceDef(namespace_dotted_name),

View File

@ -110,7 +110,7 @@ def setup_fs_project(name):
def test_get_documentable_items(): def test_get_documentable_items():
fs_root, package_name = setup_fs_project('test_get_documentable_items') fs_root, package_name = setup_fs_project('test_get_documentable_items')
pkgname, documentable = apigen.get_documentable_items( pkgname, documentable = apigen.get_documentable_items_pkgdir(
fs_root.join(package_name)) fs_root.join(package_name))
assert pkgname == 'pak' assert pkgname == 'pak'
assert sorted(documentable.keys()) == [ assert sorted(documentable.keys()) == [

View File

@ -35,13 +35,17 @@ def setup_pkg(testname):
def test_foo(): def test_foo():
assert foo(1) == 2 assert foo(1) == 2
""")) """))
initfile = pkgpath.ensure('__init__.py').write(py.code.Source("""\ initfile = pkgpath.ensure('__init__.py').write(py.code.Source("""
import py import py
from py.__.initpkg import initpkg from py.__.initpkg import initpkg
initpkg(__name__, exportdefs={ initpkg(__name__, exportdefs={
'sub.foo': ('./mod.py', 'foo'), 'sub.foo': ('./mod.py', 'foo'),
}) })
""")) """))
initfile = pkgpath.ensure('apigen/apigen.py').write(py.code.Source("""
from py.__.apigen.apigen import build, \
get_documentable_items_pkgdir as get_documentable_items
"""))
return pkgpath return pkgpath
def test_run_tests(): def test_run_tests():