@@ -148,59 +148,50 @@ def generate_file_rst(fname, target_dir, src_dir, plot_gallery):
148
148
this_template = rst_template
149
149
last_dir = os .path .split (src_dir )[- 1 ]
150
150
# 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
154
156
src_file = os .path .join (src_dir , fname )
155
157
example_file = os .path .join (target_dir , fname )
156
158
shutil .copyfile (src_file , example_file )
157
159
if plot_gallery and fname .startswith ('plot' ):
158
160
# generate the plot as png image if file name
159
161
# starts with plot and if it is more recent than an
160
162
# 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' )):
163
164
os .makedirs (os .path .join (target_dir , 'images' ))
164
165
image_file = os .path .join (target_dir , 'images' , image_name )
165
166
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 ):
168
168
print 'plotting %s' % fname
169
169
import matplotlib .pyplot as plt
170
170
plt .close ('all' )
171
171
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
183
177
if facecolor == (0.0 , 0.0 , 0.0 , 1.0 ):
184
178
plt .savefig (image_file , facecolor = 'black' )
185
179
else :
186
180
plt .savefig (image_file )
187
181
188
- try :
189
- brain .save_image (image_file )
190
- except :
191
- pass
182
+ brain .save_image (image_file )
192
183
193
184
except :
194
- print 80 * '_'
185
+ print 80 * '_'
195
186
print '%s is not compiling:' % fname
196
187
traceback .print_exc ()
197
- print 80 * '_'
188
+ print 80 * '_'
198
189
this_template = plot_rst_template
199
190
200
191
docstring , short_desc , end_row = extract_docstring (example_file )
201
192
202
- f = open (os .path .join (target_dir , fname [:- 2 ] + 'rst' ),'w' )
203
- f .write ( this_template % locals ())
193
+ f = open (os .path .join (target_dir , fname [:- 2 ] + 'rst' ), 'w' )
194
+ f .write (this_template % locals ())
204
195
f .flush ()
205
196
206
197
0 commit comments