2007-01-24 22:24:01 +08:00
|
|
|
""" run 'py.test --apigen=<this script>' to get documentation exported
|
|
|
|
|
|
|
|
exports to /tmp/output by default, set the environment variable
|
|
|
|
'APIGEN_TARGET' to override
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import py
|
2007-01-26 00:46:56 +08:00
|
|
|
import sys
|
2007-01-24 22:24:01 +08:00
|
|
|
from py.__.apigen import htmlgen
|
|
|
|
from py.__.apigen import linker
|
|
|
|
from py.__.apigen import project
|
2007-01-30 00:11:15 +08:00
|
|
|
from py.__.apigen.tracer.docstorage import pkg_to_dict
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-06 21:19:16 +08:00
|
|
|
from layout import LayoutPage
|
|
|
|
|
2007-02-04 22:35:28 +08:00
|
|
|
def get_documentable_items_pkgdir(pkgdir):
|
|
|
|
""" get all documentable items from an initpkg pkgdir
|
|
|
|
|
|
|
|
this is a generic implementation, import as 'get_documentable_items'
|
|
|
|
from your module when using initpkg to get all public stuff in the
|
|
|
|
package documented
|
|
|
|
"""
|
2007-01-26 00:46:56 +08:00
|
|
|
sys.path.insert(0, str(pkgdir.dirpath()))
|
|
|
|
rootmod = __import__(pkgdir.basename)
|
2007-02-02 07:58:57 +08:00
|
|
|
d = pkg_to_dict(rootmod)
|
2007-02-04 22:35:28 +08:00
|
|
|
return pkgdir.basename, d
|
|
|
|
|
|
|
|
def get_documentable_items(pkgdir):
|
|
|
|
pkgname, pkgdict = get_documentable_items_pkgdir(pkgdir)
|
2007-02-02 09:18:06 +08:00
|
|
|
from py.__.execnet.channel import Channel
|
2007-02-09 01:28:55 +08:00
|
|
|
pkgdict['execnet.Channel'] = Channel
|
2007-02-11 10:04:36 +08:00
|
|
|
Channel.__apigen_hide_from_nav__ = True
|
2007-02-04 22:35:28 +08:00
|
|
|
return pkgname, pkgdict
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-01 21:56:31 +08:00
|
|
|
def build(pkgdir, dsa, capture):
|
2007-02-06 21:19:16 +08:00
|
|
|
# create a linker (link database) for cross-linking
|
2007-02-07 08:24:21 +08:00
|
|
|
l = linker.TempLinker()
|
2007-02-06 21:19:16 +08:00
|
|
|
|
|
|
|
# create a project.Project instance to contain the LayoutPage instances
|
2007-01-24 22:24:01 +08:00
|
|
|
proj = project.Project()
|
|
|
|
|
2007-02-06 21:19:16 +08:00
|
|
|
# output dir
|
2007-01-24 22:24:01 +08:00
|
|
|
if 'APIGEN_TARGET' in os.environ:
|
|
|
|
targetdir = py.path.local(os.environ['APIGEN_TARGET'])
|
|
|
|
else:
|
|
|
|
targetdir = pkgdir.dirpath().join('apigen')
|
|
|
|
targetdir.ensure(dir=True)
|
|
|
|
|
2007-02-06 21:19:16 +08:00
|
|
|
# find out what to build
|
2007-01-24 22:24:01 +08:00
|
|
|
all_names = dsa._get_names(filter=lambda x, y: True)
|
|
|
|
namespace_tree = htmlgen.create_namespace_tree(all_names)
|
2007-02-06 21:19:16 +08:00
|
|
|
|
|
|
|
# and build it
|
2007-02-02 04:10:48 +08:00
|
|
|
apb = htmlgen.ApiPageBuilder(targetdir, l, dsa, pkgdir, namespace_tree,
|
2007-02-07 08:24:21 +08:00
|
|
|
proj, capture, LayoutPage)
|
|
|
|
spb = htmlgen.SourcePageBuilder(targetdir, l, pkgdir, proj, capture,
|
|
|
|
LayoutPage)
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-07 08:24:21 +08:00
|
|
|
apb.build_namespace_pages()
|
|
|
|
class_names = dsa.get_class_names()
|
|
|
|
apb.build_class_pages(class_names)
|
|
|
|
function_names = dsa.get_function_names()
|
|
|
|
apb.build_function_pages(function_names)
|
|
|
|
spb.build_pages(pkgdir)
|
|
|
|
l.replace_dirpath(targetdir)
|
|
|
|
|