/[escript]/trunk/doc/sphinx_api/genrst.py
ViewVC logotype

Annotation of /trunk/doc/sphinx_api/genrst.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5707 - (hide annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 7 months ago) by sshaw
File MIME type: text/x-python
File size: 4945 byte(s)
adding copyright headers to files without copyright info, moved header to top of file in some cases where it wasn't
1 jfenwick 4110 #!/usr/bin/env python
2 sshaw 5707 ##############################################################################
3     #
4     # Copyright (c) 2003-2015 by The University of Queensland
5     # http://www.uq.edu.au
6     #
7     # Primary Business: Queensland, Australia
8     # Licensed under the Open Software License version 3.0
9     # http://www.opensource.org/licenses/osl-3.0.php
10     #
11     # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14     #
15     ##############################################################################
16    
17 sshaw 5706 from __future__ import division, print_function
18 jfenwick 4110
19 jfenwick 4101 import os
20     import inspect
21 jfenwick 4107 import sys
22 jfenwick 4101
23 jfenwick 4107 if len(sys.argv)!=4:
24     sys.stderr.write('Usage: startdir startpackage outputdirectory\n')
25     sys.exit(1)
26 jfenwick 4101
27 jfenwick 4107 #startdir='./esys'
28     #startpackage='esys'
29     #outdir='doctest'
30 jfenwick 4101
31 jfenwick 4141 pathdir=sys.argv[1]
32 jfenwick 4107 startpackage=sys.argv[2]
33 jfenwick 4141 startdir=os.path.join(pathdir, startpackage)
34 jfenwick 4107 outdir=sys.argv[3]
35    
36 jfenwick 4398 def dumpPackage(mname, ignorelist, modset, banset):
37 sshaw 4580 try:
38     exec('import '+mname+' as PP')
39     except ImportError:
40     return
41 jfenwick 4297 modset.add(mname)
42 jfenwick 4853 print("Starting dump on "+mname+' with ignore at '+str(ignorelist))
43 jfenwick 4297 pack=open(os.path.join(outdir,mname+'.rst'),'w')
44     pack.write(mname+' Package\n')
45     pack.write('='*len(mname)+'========\n\n')
46 sshaw 5575 # pack.write('.. py:module:: '+mname+'\n\n')
47 sshaw 5288 moddoc = inspect.getdoc(PP)
48     if moddoc:
49 sshaw 5575 pack.write(".. automodule:: %s\n :synopsis: %s\n"%(mname, "".join(moddoc.replace("\n\n", "\n").replace("\n", " "))))
50 jfenwick 4297 #Automodule does not seem to do what we want so we need to drill down
51     clist=[]
52     flist=[]
53     vlist=[]
54 jfenwick 4398 norecurse=[]
55     try:
56     norecurse=PP.__nodocorecursion
57 jfenwick 4853 print("Supressing the following packages")
58 jfenwick 4398 for n in norecurse:
59 jfenwick 4853 print(mname+'.'+n)
60 jfenwick 4398 banset.add(mname+'.'+n)
61 jfenwick 4853 print('---------')
62 jfenwick 4398 except AttributeError:
63     pass
64 jfenwick 4396 # esys.escript.models does not get picked up by this loop
65 jfenwick 4297 for (name, mem) in inspect.getmembers(PP):
66 jfenwick 4853 print(" "+name)
67 jfenwick 4297 if inspect.ismodule(mem):
68     if not name in ignorelist:
69     try:
70     ppfile=inspect.getfile(PP)
71     memfile=inspect.getfile(mem)
72     except:
73     continue #It will be a builtin module
74     ppdir=ppfile[:ppfile.rfind(os.path.sep)]
75     memdir=memfile[:memfile.rfind(os.path.sep)]
76     if ppdir==memdir:
77 jfenwick 4396 if not mem.__name__ in modset:
78 jfenwick 4398 if not mem.__name__ in banset:
79 jfenwick 4853 print("About to dump "+name+"("+mem.__name__+")")
80 jfenwick 4398 dumpPackage(mem.__name__, [], modset, banset)
81 jfenwick 4853 print("Dump of "+mname+" complete")
82 sshaw 4576 #pack.write('Module '+name+'\n')
83 jfenwick 4297 elif inspect.isclass(mem):
84 sshaw 4576 clist+=[(name, mem)]
85 jfenwick 4297 elif inspect.isfunction(mem):
86 sshaw 4576 flist+=[(name, mem)]
87 jfenwick 4297 else:
88 sshaw 4576 if type(mem).__module__+'.'+type(mem).__name__=='Boost.Python.function':
89     flist+=[(name, mem)]
90     else:
91     vlist+=[(name, mem)]
92 sshaw 5575 pack.write('\nClasses\n')
93 jfenwick 4297 pack.write('-------\n')
94     for (name, mem) in clist:
95     pack.write('* `'+name+'`\n')
96     pack.write('\n')
97     for (name, mem) in clist:
98     pack.write('.. autoclass:: '+name+'\n')
99 sshaw 5575 pack.write(' :members:\n :undoc-members:\n\n .. automethod:: __init__\n\n')
100 jfenwick 4297 pack.write('\n')
101    
102     pack.write('Functions\n')
103     pack.write('---------\n')
104     for (name, mem) in flist:
105     pack.write('.. autofunction:: '+name+'\n')
106     pack.write('\n')
107    
108     pack.write('Others\n')
109     pack.write('------\n')
110     for (name, mem) in vlist:
111     pack.write('* '+name+'\n')
112     pack.write('\n')
113     pack.close()
114    
115 jfenwick 4101 def listmods():
116     W=os.walk(startdir,topdown=True)
117 jfenwick 4141 sys.path.append(pathdir)
118 jfenwick 4101 main=open(os.path.join(outdir,'index.rst'),'w')
119     main.write('.. Generated by Joel\'s script\n\n')
120     main.write('Documentation for esys.escript\n')
121     main.write('==============================\n')
122     main.write('\n')
123     main.write('Contents:\n\n')
124     main.write('.. toctree::\n')
125     main.write(' :maxdepth: 4\n')
126     main.write('\n')
127 jfenwick 4297 modset=set()
128 jfenwick 4398 banset=set()
129 jfenwick 4101 for z in W:
130 jfenwick 4290 if z[0].endswith('__pycache__'): continue
131 jfenwick 4396 #if z[0].find('escript')==-1: continue
132 jfenwick 4853 print("Beginning ",z[0])
133 jfenwick 4101 # Now make the package name
134     n=startpackage+'.'.join(z[0][len(startdir):].split(os.path.sep))
135 jfenwick 4398 dumpPackage(n, z[1], modset, banset)
136 jfenwick 4853 print("-------------"+n)
137 jfenwick 4101
138 sshaw 4576 for m in z[2]: #This will list the files
139 jfenwick 4101 if m.split('.')[1]=='pyc' and m!='__init__.pyc':
140 jfenwick 4853 print(".."+n+"."+m)
141     print(".."+(n+'.'+m)[:-4])
142 sshaw 4576 if not (n+'.'+m)[:-4] in banset:
143     dumpPackage((n+'.'+m)[:-4],[],modset, banset)
144 jfenwick 4297 l=list(modset)
145     l.sort()
146     for n in l:
147     main.write(" "+n+"\n")
148 jfenwick 4101 main.write('\n')
149 caltinay 4129 main.write('Indices and Tables\n')
150     main.write('==================\n')
151 jfenwick 4101 main.write('\n')
152     main.write('* :ref:`genindex`\n')
153     main.write('* :ref:`modindex`\n')
154     main.write('\n')
155 sshaw 4576 main.close()
156 jfenwick 4101
157    
158 jfenwick 4110 listmods()

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26