1
2 """
3 Generate epydoc documentation of IvS repository and insert images.
4
5 The documentation will be stored in the subdirectory "doc/html" of the IvS root
6 directory (i.e. where this file is located). If previously generated
7 documentation exists, it will be overwriten.
8
9 The main page of the documentation can be found in "doc/html/index.html".
10
11 Updating the documentation is a simple as rerunning the script, you do not need
12 to delete the results from the previous run.
13
14 For more command-line options, see
15
16 $:> python makedoc.py -h
17 """
18
19 import os
20 import subprocess
21 import shutil
22 import glob
23 import webbrowser
24 import sys
25 import argparse
26 from ivs.aux import termtools
27
28
29
30 skip = ['uncertainties','lmfit']
31
32
33
34 parser = argparse.ArgumentParser(description='Build IvS Python repository documentation')
35 parser.add_argument('-o','--open',action='store_true',help='Open documentation in webbrowser after creation')
36 parser.add_argument('-v','--verbose',action='store_true',help='Increase output verbosity in Epydoc')
37 parser.add_argument('-w','--width',type=int,default=75,help='Width of images (percentage)')
38 args = parser.parse_args()
39
40
41
42 this_dir = os.path.dirname(os.path.abspath(__file__))
43
44
45 output = subprocess.check_output('git ls-files',shell=True)
46 alldirs = output.strip().split('\n')
47
48
49
50 alldirs = [ff for ff in alldirs if os.path.splitext(ff)[1]=='.py' and not os.path.basename(ff)[:4]=='test']
51 for iskip in skip:
52 alldirs = [ff for ff in alldirs if not iskip in ff]
53
54
55 cmd = 'epydoc --html '+" ".join(alldirs)+\
56 ' -o doc/html --parse-only --graph all {}'.format('-v' if args.verbose else '')
57 print("Building documentation using the command:\n {}".format(cmd))
58 flag = subprocess.call(cmd,shell=True)
59
60
61 if flag:
62 print("Could not execute command, do you have epydoc installed?")
63 raise SystemExit
64
65
66
67
68
69 if not os.path.isdir('doc/images'):
70 print("You don't have an image directory; images are not inserted")
71 raise SystemExit
72
73
74
75 '''shutil.move('doc/html/ivs.timeseries.freqanalyse-module.html','doc/html/ivs.timeseries.freqanalyse-module_.html')
76 ff = open('doc/html/ivs.timeseries.freqanalyse-module_.html','r')
77 oo = open('doc/html/ivs.timeseries.freqanalyse-module.html','w')
78 ESC = chr(27)
79 for line in ff.readlines():
80 if r'p = pl.ylim(0,0.018)' in line:
81 oo.write(line+'\n\n')
82 oo.write(r"<center><img src='../images/timeseries_freqanalyse_01.png' alt='[image example]' /></center>"+'\n\n')
83 #-- save cursor, remove line, print and reset cursor
84 message = 'Added image to ivs.timeseries.freqanalyse'
85 termtools.overwrite_line(message)
86 else:
87 oo.write(line)
88 ff.close()
89 oo.close()
90 os.remove('doc/html/ivs.timeseries.freqanalyse-module_.html')'''
91
92
93 files = sorted(glob.glob('doc/html/*module.html'))
94 files+= sorted(glob.glob('doc/html/*class.html'))
95 for myfile in files:
96 shutil.move(myfile,myfile+'_')
97 ff = open(myfile+'_','r')
98 oo = open(myfile,'w')
99
100 line_break = False
101 for line in ff.readlines():
102
103 if ']include figure]' in line or line_break:
104 filename = line.split(']')[-2].strip()
105 oo.write(r"<center><img src='../images/{}' alt='[image example]' width='{}%'/></center>".format(filename,args.width)+'\n\n')
106
107 message = 'Added image {} to {}\r'.format(filename,myfile)
108 termtools.overwrite_line(message)
109 oo.write('\n\n')
110 line_break = False
111
112 elif ']include' in line:
113 line_break = True
114
115 else:
116 oo.write(line)
117
118 ff.close()
119 oo.close()
120 os.remove(myfile+'_')
121
122 if os.path.isfile(os.path.join(this_dir,'doc/html/index.html')):
123 print("HTML documentation is now available in doc/html")
124 else:
125 print("Something went wrong during documentation generation")
126 raise SystemExit
127 if args.open:
128 print("Documentation will be opened in your default webbrowser")
129 webbrowser.open_new_tab('doc/html/index.html')
130