@@ -117,7 +117,7 @@ def extract_docstring(filename):
117117 first_par = paragraphs [0 ]
118118 break
119119 end_row = erow + 1 + start_row
120- if lines and lines [end_row - 2 ] == 'print __doc__\n ' :
120+ if lines and lines [end_row - 2 ] == 'print( __doc__) \n ' :
121121 end_row += 1
122122 return docstring , first_par , end_row
123123
@@ -171,6 +171,10 @@ def generate_example_rst(app):
171171 </style>
172172
173173.. _examples-index:
174+
175+ Examples
176+ ========
177+
174178""" )
175179 # Here we don't use an os.walk, but we recurse only twice: flat is
176180 # better than nested.
@@ -191,11 +195,9 @@ def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery):
191195 target_dir = root_dir
192196 src_dir = example_dir
193197 if not os .path .exists (os .path .join (src_dir , 'README.txt' )):
194- print 80 * '_'
195- print ('Example directory %s does not have a README.txt file'
196- % src_dir )
197- print 'Skipping this directory'
198- print 80 * '_'
198+ print ('Example directory %s does not have a README.txt file' % src_dir )
199+ print ('Skipping this directory' )
200+ print (80 * '_' )
199201 return
200202 fhindex .write ("""
201203
@@ -212,6 +214,12 @@ def sort_key(a):
212214 if not a .startswith ('plot' ) and a .endswith ('.py' ):
213215 return 'zz' + a
214216 return a
217+
218+ fhindex .write ("""
219+
220+ .. toctree::
221+
222+ """ )
215223 for fname in sorted (os .listdir (src_dir ), key = sort_key ):
216224 if fname .endswith ('py' ):
217225 generate_file_rst (fname , target_dir , src_dir , plot_gallery )
@@ -226,13 +234,10 @@ def sort_key(a):
226234 #else:
227235 # fhindex.write(' :target: ./%s.html\n\n' % link_name[:-3])
228236 fhindex .write ("""
229-
230- .. toctree::
231-
232237 %s/%s
233-
234238""" % (dir , fname [:- 3 ]))
235239 fhindex .write ("""
240+
236241.. raw:: html
237242
238243 <div style="clear: both"></div>
@@ -295,7 +300,7 @@ def generate_file_rst(fname, target_dir, src_dir, plot_gallery):
295300 os .stat (first_image_file ).st_mtime <=
296301 os .stat (src_file ).st_mtime ):
297302 # We need to execute the code
298- print 'plotting %s' % fname
303+ print ( 'plotting %s' % fname )
299304 t0 = time ()
300305 import matplotlib .pyplot as plt
301306 plt .close ('all' )
@@ -341,20 +346,26 @@ def generate_file_rst(fname, target_dir, src_dir, plot_gallery):
341346 plt .savefig (image_path % fig_num )
342347 figure_list .append (image_fname % fig_num )
343348 for canvas in ROOT .gROOT .GetListOfCanvases ():
344- canvas .SaveAs (root_image_path % root_fig_num )
345- canvas .Close ()
346- figure_list .append (root_image_fname % root_fig_num )
347- root_fig_num += 1
349+ maybe_root_filename = os .path .join (os .path .dirname (src_file ), canvas .name )
350+ if os .path .isfile (maybe_root_filename ):
351+ os .rename (maybe_root_filename , os .path .join (image_dir , canvas .name ))
352+ figure_list .append (canvas .name )
353+ canvas .Close ()
354+ else :
355+ canvas .SaveAs (root_image_path % root_fig_num )
356+ canvas .Close ()
357+ figure_list .append (root_image_fname % root_fig_num )
358+ root_fig_num += 1
348359 except :
349- print 80 * '_'
350- print '%s is not compiling:' % fname
360+ print ( 80 * '_' )
361+ print ( '%s is not compiling:' % fname )
351362 traceback .print_exc ()
352- print 80 * '_'
363+ print ( 80 * '_' )
353364 finally :
354365 os .chdir (cwd )
355366 sys .stdout = orig_stdout
356367
357- print " - time elapsed : %.2g sec" % time_elapsed
368+ print ( " - time elapsed : %.2g sec" % time_elapsed )
358369 else :
359370 figure_list = [f [len (image_dir ):]
360371 for f in glob .glob (image_path % '[1-9]' )]
0 commit comments