view doc/scripts/docgen.py @ 1523:0e0f9e8275a9

add link to the github pylearn.
author Frederic Bastien <nouiz@nouiz.org>
date Fri, 02 Nov 2012 12:53:08 -0400
parents 57feab73c783
children
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)

    if not (options['--epydoc'] or options['--rst']):
        # Default is now rst
        options['--rst'] = True

    def mkdir(path):
        try:
            os.mkdir(path)
        except OSError:
            pass

    outdir = options['-o'] or (pylearn_root + '/html')
    mkdir(outdir)
    os.chdir(outdir)

    # 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']:
        mkdir("api")
        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']:
        mkdir("doc")
        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