Skip to content

Commit 114062f

Browse files
Nikolay Mayorovogrisel
authored andcommitted
Explicit encoding for opened files in gen_rst.py
1 parent f7efb1a commit 114062f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

doc/sphinxext/gen_rst.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
execfile
4343
except NameError:
4444
def execfile(filename, global_vars=None, local_vars=None):
45-
with open(filename) as f:
45+
with open(filename, encoding='utf-8') as f:
4646
code = compile(f.read(), filename, 'exec')
4747
exec(code, global_vars, local_vars)
4848

@@ -426,7 +426,7 @@ def resolve(self, cobj, this_url):
426426
def extract_docstring(filename, ignore_heading=False):
427427
""" Extract a module-level docstring, if any
428428
"""
429-
lines = open(filename).readlines()
429+
lines = open(filename, encoding='utf-8').readlines()
430430
start_row = 0
431431
if lines[0].startswith('#!'):
432432
lines.pop(0)
@@ -522,7 +522,7 @@ def generate_example_rst(app):
522522
def extract_line_count(filename, target_dir):
523523
# Extract the line count of a file
524524
example_file = os.path.join(target_dir, filename)
525-
lines = open(example_file).readlines()
525+
lines = open(example_file, encoding='utf-8').readlines()
526526
start_row = 0
527527
if lines and lines[0].startswith('#!'):
528528
lines.pop(0)
@@ -955,7 +955,8 @@ def generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery):
955955
f.flush()
956956

957957
# save variables so we can later add links to the documentation
958-
example_code_obj = identify_names(open(example_file).read())
958+
example_code_obj = \
959+
identify_names(open(example_file, encoding='utf-8').read())
959960
if example_code_obj:
960961
codeobj_fname = example_file[:-3] + '_codeobj.pickle'
961962
with open(codeobj_fname, 'wb') as fid:

0 commit comments

Comments
 (0)