@@ -148,66 +148,51 @@ def generate_file_rst(fname, target_dir, src_dir, plot_gallery):
148148 this_template = rst_template
149149 last_dir = os .path .split (src_dir )[- 1 ]
150150 # to avoid leading . in file names
151- if last_dir == '.' : last_dir = ''
152- else : last_dir += '_'
153- short_fname = last_dir + fname
151+ if last_dir == '.' :
152+ last_dir = ''
153+ else :
154+ last_dir += '_'
155+ short_fname = last_dir + fname
154156 src_file = os .path .join (src_dir , fname )
155157 example_file = os .path .join (target_dir , fname )
156158 shutil .copyfile (src_file , example_file )
157159 if plot_gallery and fname .startswith ('plot' ):
158160 # generate the plot as png image if file name
159161 # starts with plot and if it is more recent than an
160162 # existing image.
161- if not os .path .exists (
162- os .path .join (target_dir , 'images' )):
163+ if not os .path .exists (os .path .join (target_dir , 'images' )):
163164 os .makedirs (os .path .join (target_dir , 'images' ))
164165 image_file = os .path .join (target_dir , 'images' , image_name )
165166 if (not os .path .exists (image_file ) or
166- os .stat (image_file ).st_mtime <=
167- os .stat (src_file ).st_mtime ):
167+ os .stat (image_file ).st_mtime <= os .stat (src_file ).st_mtime ):
168168 print 'plotting %s' % fname
169169 import matplotlib .pyplot as plt
170170 plt .close ('all' )
171171 try :
172- try :
173- from mayavi import mlab
174- except ImportError :
175- from enthought .mayavi import mlab
176- mlab .close (all = True )
177- except :
178- pass
179-
180- try :
181- execfile (example_file , {'pl' : plt })
182- facecolor = plt .gcf ().get_facecolor () # hack to keep black bg
172+ brain = None
173+ global plt
174+ global brain
175+ execfile (example_file , globals ())
176+ facecolor = plt .gcf ().get_facecolor () # hack to keep black bg
183177 if facecolor == (0.0 , 0.0 , 0.0 , 1.0 ):
184178 plt .savefig (image_file , facecolor = 'black' )
185179 else :
186180 plt .savefig (image_file )
187181
188- try :
189- try :
190- from mayavi import mlab
191- except ImportError :
192- from enthought .mayavi import mlab
193-
194- e = mlab .get_engine ()
195- if len (e .scenes ) > 0 :
196- mlab .savefig (image_file , size = (400 , 400 ))
197- except :
198- pass
182+ brain .save_image (image_file )
183+ brain .close ()
199184
200185 except :
201- print 80 * '_'
186+ print 80 * '_'
202187 print '%s is not compiling:' % fname
203188 traceback .print_exc ()
204- print 80 * '_'
189+ print 80 * '_'
205190 this_template = plot_rst_template
206191
207192 docstring , short_desc , end_row = extract_docstring (example_file )
208193
209- f = open (os .path .join (target_dir , fname [:- 2 ] + 'rst' ),'w' )
210- f .write ( this_template % locals ())
194+ f = open (os .path .join (target_dir , fname [:- 2 ] + 'rst' ), 'w' )
195+ f .write (this_template % locals ())
211196 f .flush ()
212197
213198
0 commit comments