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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26