@@ -181,24 +181,23 @@ def generate_gallery_rst(app):
181
181
computation_times += this_computation_times
182
182
183
183
# we create an index.rst with all examples
184
- fhindex = open (os .path .join (gallery_dir , 'index.rst' ), 'w' )
185
- # :orphan: to suppress "not included in TOCTREE" sphinx warnings
186
- fhindex .write (":orphan:\n \n " + this_fhindex )
187
- for directory in sorted (os .listdir (examples_dir )):
188
- if os .path .isdir (os .path .join (examples_dir , directory )):
189
- src_dir = os .path .join (examples_dir , directory )
190
- target_dir = os .path .join (gallery_dir , directory )
191
- this_fhindex , this_computation_times = generate_dir_rst (src_dir , target_dir , gallery_conf ,
192
- seen_backrefs )
193
- fhindex .write (this_fhindex )
194
- computation_times += this_computation_times
195
-
196
- if gallery_conf ['download_all_examples' ]:
197
- download_fhindex = generate_zipfiles (gallery_dir )
198
- fhindex .write (download_fhindex )
199
-
200
- fhindex .write (SPHX_GLR_SIG )
201
- fhindex .flush ()
184
+ with open (os .path .join (gallery_dir , 'index.rst' ), 'wb' ) as fhindex :
185
+ # :orphan: to suppress "not included in TOCTREE" sphinx warnings
186
+ fhindex .write ((u":orphan:\n \n " + this_fhindex ).encode ('utf-8' ))
187
+ for directory in sorted (os .listdir (examples_dir )):
188
+ if os .path .isdir (os .path .join (examples_dir , directory )):
189
+ src_dir = os .path .join (examples_dir , directory )
190
+ target_dir = os .path .join (gallery_dir , directory )
191
+ this_fhindex , this_computation_times = generate_dir_rst (src_dir , target_dir , gallery_conf ,
192
+ seen_backrefs )
193
+ fhindex .write (this_fhindex .encode ('utf-8' ))
194
+ computation_times += this_computation_times
195
+
196
+ if gallery_conf ['download_all_examples' ]:
197
+ download_fhindex = generate_zipfiles (gallery_dir )
198
+ fhindex .write (download_fhindex .encode ('utf-8' ))
199
+
200
+ fhindex .write (SPHX_GLR_SIG )
202
201
203
202
if gallery_conf ['plot_gallery' ]:
204
203
print ("Computation time summary:" )
0 commit comments