Menu

#59 Documentation Enhancement

open
Other (25)
5
2007-03-16
2007-03-16
No

I found myself needing to embed epydoc in a program I'm working on. I wanted to have epydoc called directly, without invoking a separate process. This was actually harder than I had anticipated. Here's the code I used, which others might find helpful:

-----<cut here>-----
def drvepydoc(docindex, check, ns):
from epydoc.cli import write_html, check_docs, parse_arguments
if (check):
sys.argv = ["--check"]
else:
sys.argv = ["--html"]
sys.argv.extend(ns)
options, names = parse_arguments()
if (check):
check_docs(docindex, options)
else:
write_html(docindex, options)

def runepydoc(ns):
from epydoc.docbuilder import build_doc_index
from epydoc import log
from epydoc.cli import UnifiedProgressConsoleLogger
stages = [40, 7, 1, 3, 30, 1, 2, 50] # Stages taken directly from epydoc.cli, with one added in (50) for processing docs/html
logger = UnifiedProgressConsoleLogger(0, stages)
log.register_logger(logger)
docindex = build_doc_index(ns, True, True, add_submodules=True, exclude_introspect='', exclude_parse='')
drvepydoc(docindex, False, ns)
drvepydoc(docindex, True, ns)
log.close()

-----<cut here>-----

Minor gotchas: Your program *must* be in the same directory for which you are documenting (can not be in /home/me and trying to document /tmp/pydir).

os.chdir("/tmp/pydir")

ns (for runepydoc) is a list of modules to document.

ns = ["module1", "module2"]

Once those are set, simply call runepydoc with that list.

runepydoc(ns)

Hopefully, it will be helpful to others.

Discussion


Log in to post a comment.