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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4580 - (show annotations)
Tue Dec 10 06:10:44 2013 UTC (6 years, 6 months ago) by sshaw
File MIME type: text/x-python
File size: 4092 byte(s)
fixed doc building relying on potentially missing python package installs (bug #739)
1 #!/usr/bin/env python
2
3 import os
4 import inspect
5 import sys
6
7 if len(sys.argv)!=4:
8 sys.stderr.write('Usage: startdir startpackage outputdirectory\n')
9 sys.exit(1)
10
11 #startdir='./esys'
12 #startpackage='esys'
13 #outdir='doctest'
14
15 pathdir=sys.argv[1]
16 startpackage=sys.argv[2]
17 startdir=os.path.join(pathdir, startpackage)
18 outdir=sys.argv[3]
19
20 def dumpPackage(mname, ignorelist, modset, banset):
21 try:
22 exec('import '+mname+' as PP')
23 except ImportError:
24 return
25 modset.add(mname)
26 print "Starting dump on "+mname+' with ignore at '+str(ignorelist)
27 pack=open(os.path.join(outdir,mname+'.rst'),'w')
28 pack.write(mname+' Package\n')
29 pack.write('='*len(mname)+'========\n\n')
30 pack.write('.. py:module:: '+mname+'\n\n')
31 #Automodule does not seem to do what we want so we need to drill down
32 clist=[]
33 flist=[]
34 vlist=[]
35 norecurse=[]
36 try:
37 norecurse=PP.__nodocorecursion
38 print "Supressing the following packages"
39 for n in norecurse:
40 print mname+'.'+n
41 banset.add(mname+'.'+n)
42 print '---------'
43 except AttributeError:
44 pass
45 # esys.escript.models does not get picked up by this loop
46 for (name, mem) in inspect.getmembers(PP):
47 print " "+name
48 if inspect.ismodule(mem):
49 if not name in ignorelist:
50 try:
51 ppfile=inspect.getfile(PP)
52 memfile=inspect.getfile(mem)
53 except:
54 continue #It will be a builtin module
55 ppdir=ppfile[:ppfile.rfind(os.path.sep)]
56 memdir=memfile[:memfile.rfind(os.path.sep)]
57 if ppdir==memdir:
58 if not mem.__name__ in modset:
59 if not mem.__name__ in banset:
60 print "About to dump "+name+"("+mem.__name__+")"
61 dumpPackage(mem.__name__, [], modset, banset)
62 print "Dump of "+mname+" complete"
63 #pack.write('Module '+name+'\n')
64 elif inspect.isclass(mem):
65 clist+=[(name, mem)]
66 elif inspect.isfunction(mem):
67 flist+=[(name, mem)]
68 else:
69 if type(mem).__module__+'.'+type(mem).__name__=='Boost.Python.function':
70 flist+=[(name, mem)]
71 else:
72 vlist+=[(name, mem)]
73 pack.write('Classes\n')
74 pack.write('-------\n')
75 for (name, mem) in clist:
76 pack.write('* `'+name+'`\n')
77 pack.write('\n')
78 for (name, mem) in clist:
79 pack.write('.. autoclass:: '+name+'\n')
80 pack.write(' :members:\n :undoc-members:\n\n')
81 pack.write('\n')
82
83 pack.write('Functions\n')
84 pack.write('---------\n')
85 for (name, mem) in flist:
86 pack.write('.. autofunction:: '+name+'\n')
87 pack.write('\n')
88
89 pack.write('Others\n')
90 pack.write('------\n')
91 for (name, mem) in vlist:
92 pack.write('* '+name+'\n')
93 pack.write('\n')
94 pack.close()
95
96 def listmods():
97 W=os.walk(startdir,topdown=True)
98 sys.path.append(pathdir)
99 main=open(os.path.join(outdir,'index.rst'),'w')
100 main.write('.. Generated by Joel\'s script\n\n')
101 main.write('Documentation for esys.escript\n')
102 main.write('==============================\n')
103 main.write('\n')
104 main.write('Contents:\n\n')
105 main.write('.. toctree::\n')
106 main.write(' :maxdepth: 4\n')
107 main.write('\n')
108 modset=set()
109 banset=set()
110 for z in W:
111 if z[0].endswith('__pycache__'): continue
112 #if z[0].find('escript')==-1: continue
113 print "Beginning ",z[0]
114 # Now make the package name
115 n=startpackage+'.'.join(z[0][len(startdir):].split(os.path.sep))
116 dumpPackage(n, z[1], modset, banset)
117 print "-------------"+n
118
119 for m in z[2]: #This will list the files
120 if m.split('.')[1]=='pyc' and m!='__init__.pyc':
121 print ".."+n+"."+m
122 print ".."+(n+'.'+m)[:-4]
123 if not (n+'.'+m)[:-4] in banset:
124 dumpPackage((n+'.'+m)[:-4],[],modset, banset)
125 l=list(modset)
126 l.sort()
127 for n in l:
128 main.write(" "+n+"\n")
129 main.write('\n')
130 main.write('Indices and Tables\n')
131 main.write('==================\n')
132 main.write('\n')
133 main.write('* :ref:`genindex`\n')
134 main.write('* :ref:`modindex`\n')
135 main.write('\n')
136 main.close()
137
138
139 listmods()

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26