Mercurial > pylearn
view doc/scripts/docgen.py @ 1240:317049b21b77
RST in API_learner
author | Pascal Lamblin <lamblinp@iro.umontreal.ca> |
---|---|
date | Thu, 23 Sep 2010 12:02:16 -0400 |
parents | 9472d234db2e |
children | 57feab73c783 |
line wrap: on
line source
import sys import os import shutil import inspect from epydoc import docintrospecter from epydoc.apidoc import RoutineDoc import getopt from collections import defaultdict if __name__ == '__main__': # make sure we're in the right directory this_file_directory = os.path.abspath(os.path.dirname(__file__)) pylearn_root = os.path.join(os.path.join(this_file_directory, ".."), "..") #pylearn_root = "/".join(sys.path[0].split("/")[:-2]) options = defaultdict(bool) options.update(dict([x, y or True] for x, y in getopt.getopt(sys.argv[1:], 'o:', ['epydoc', 'rst', 'help', 'nopdf'])[0])) if options['--help']: print 'Usage: %s [OPTIONS]' % sys.argv[0] print ' -o <dir>: output the html files in the specified dir' print ' --rst: only compile the doc (requires sphinx)' print ' --nopdf: do not produce a PDF file from the doc, only HTML' print ' --epydoc: only compile the api documentation (requires epydoc)' print ' --help: this help' sys.exit(0) options['--all'] = not (bool(options['--epydoc']) ^ bool(options['--rst'])) def mkdir(path): try: os.mkdir(path) except OSError: pass outdir = options['-o'] or (pylearn_root + '/html') mkdir(outdir) os.chdir(outdir) mkdir("doc") mkdir("api") # Make sure the appropriate 'theano' directory is in the PYTHONPATH pythonpath = os.environ.get('PYTHONPATH', '') pythonpath = pylearn_root + ':' + pythonpath os.environ['PYTHONPATH'] = pythonpath if options['--all'] or options['--epydoc']: from epydoc.cli import cli sys.path[0:0] = [pylearn_root] #Generate HTML doc ## This causes problems with the subsequent generation of sphinx doc #sys.argv[:] = ['', '--config', '%s/doc/api/epydoc.conf' % pylearn_root, '-o', 'api'] #cli() ## So we use this instead os.system("epydoc --config %s/doc/api/epydoc.conf -o api" % pylearn_root) # Generate PDF doc # TODO if options['--all'] or options['--rst']: import sphinx sys.path[0:0] = [os.path.join(pylearn_root, 'doc')] sphinx.main(['', '-E', os.path.join(pylearn_root, 'doc'), '.']) if not options['--nopdf']: # Generate latex file in a temp directory import tempfile workdir = tempfile.mkdtemp() sphinx.main(['', '-E', '-b', 'latex', os.path.join(pylearn_root, 'doc'), workdir]) # Compile to PDF os.chdir(workdir) os.system('make') try: shutil.copy(os.path.join(workdir, 'pylearn.pdf'), outdir) os.chdir(outdir) shutil.rmtree(workdir) except OSError, e: print 'OSError:', e except IOError, e: print 'IOError:', e