comparison doc/scripts/docgen.py @ 908:9472d234db2e

Added basics for documentation with sphinx and epydoc, by copying files from the Theano/doc directory
author fsavard
date Thu, 18 Mar 2010 11:33:49 -0400
parents
children 57feab73c783
comparison
equal deleted inserted replaced
904:08b37147dec1 908:9472d234db2e
1 import sys
2 import os
3 import shutil
4 import inspect
5
6 from epydoc import docintrospecter
7 from epydoc.apidoc import RoutineDoc
8
9 import getopt
10 from collections import defaultdict
11
12 if __name__ == '__main__':
13
14 # make sure we're in the right directory
15 this_file_directory = os.path.abspath(os.path.dirname(__file__))
16 pylearn_root = os.path.join(os.path.join(this_file_directory, ".."), "..")
17
18 #pylearn_root = "/".join(sys.path[0].split("/")[:-2])
19
20 options = defaultdict(bool)
21 options.update(dict([x, y or True] for x, y in getopt.getopt(sys.argv[1:], 'o:', ['epydoc', 'rst', 'help', 'nopdf'])[0]))
22 if options['--help']:
23 print 'Usage: %s [OPTIONS]' % sys.argv[0]
24 print ' -o <dir>: output the html files in the specified dir'
25 print ' --rst: only compile the doc (requires sphinx)'
26 print ' --nopdf: do not produce a PDF file from the doc, only HTML'
27 print ' --epydoc: only compile the api documentation (requires epydoc)'
28 print ' --help: this help'
29 sys.exit(0)
30
31 options['--all'] = not (bool(options['--epydoc']) ^ bool(options['--rst']))
32
33 def mkdir(path):
34 try:
35 os.mkdir(path)
36 except OSError:
37 pass
38
39 outdir = options['-o'] or (pylearn_root + '/html')
40 mkdir(outdir)
41 os.chdir(outdir)
42 mkdir("doc")
43 mkdir("api")
44
45 # Make sure the appropriate 'theano' directory is in the PYTHONPATH
46 pythonpath = os.environ.get('PYTHONPATH', '')
47 pythonpath = pylearn_root + ':' + pythonpath
48 os.environ['PYTHONPATH'] = pythonpath
49
50 if options['--all'] or options['--epydoc']:
51 from epydoc.cli import cli
52 sys.path[0:0] = [pylearn_root]
53
54 #Generate HTML doc
55
56 ## This causes problems with the subsequent generation of sphinx doc
57 #sys.argv[:] = ['', '--config', '%s/doc/api/epydoc.conf' % pylearn_root, '-o', 'api']
58 #cli()
59 ## So we use this instead
60 os.system("epydoc --config %s/doc/api/epydoc.conf -o api" % pylearn_root)
61
62 # Generate PDF doc
63 # TODO
64
65 if options['--all'] or options['--rst']:
66 import sphinx
67 sys.path[0:0] = [os.path.join(pylearn_root, 'doc')]
68 sphinx.main(['', '-E', os.path.join(pylearn_root, 'doc'), '.'])
69
70 if not options['--nopdf']:
71 # Generate latex file in a temp directory
72 import tempfile
73 workdir = tempfile.mkdtemp()
74 sphinx.main(['', '-E', '-b', 'latex',
75 os.path.join(pylearn_root, 'doc'), workdir])
76 # Compile to PDF
77 os.chdir(workdir)
78 os.system('make')
79 try:
80 shutil.copy(os.path.join(workdir, 'pylearn.pdf'), outdir)
81 os.chdir(outdir)
82 shutil.rmtree(workdir)
83 except OSError, e:
84 print 'OSError:', e
85 except IOError, e:
86 print 'IOError:', e
87
88
89