Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cec3991

Browse files
committed
FIX: Use unicode
1 parent bac1d6e commit cec3991

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

sphinx_gallery/gen_gallery.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,23 @@ def generate_gallery_rst(app):
181181
computation_times += this_computation_times
182182

183183
# 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)
202201

203202
if gallery_conf['plot_gallery']:
204203
print("Computation time summary:")

sphinx_gallery/gen_rst.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ def generate_dir_rst(src_dir, target_dir, gallery_conf, seen_backrefs):
399399
print(80 * '_')
400400
return "", [] # because string is an expected return type
401401

402-
with open(os.path.join(src_dir, 'README.txt')) as fid:
403-
fhindex = fid.read()
402+
with open(os.path.join(src_dir, 'README.txt'), 'rb') as fid:
403+
fhindex = fid.read().decode('utf-8')
404404
# Add empty lines to avoid bug in issue #165
405405
fhindex += "\n\n"
406406

0 commit comments

Comments
 (0)