diff --git a/docs/autogen.py b/docs/autogen.py index 22964a17a262..d6f8b4bff65e 100644 --- a/docs/autogen.py +++ b/docs/autogen.py @@ -269,7 +269,7 @@ def add_np_implementation(function, docstring): def read_file(path): - with open(path) as f: + with open(path, encoding='utf-8') as f: return f.read() @@ -326,7 +326,7 @@ def get_module_docstring(filepath): Also finds the line at which the docstring ends. """ - co = compile(open(filepath).read(), filepath, 'exec') + co = compile(open(filepath, encoding='utf-8').read(), filepath, 'exec') if co.co_consts and isinstance(co.co_consts[0], six.string_types): docstring = co.co_consts[0] else: @@ -347,8 +347,9 @@ def copy_examples(examples_dir, destination_dir): module_path = os.path.join(examples_dir, file) docstring, starting_line = get_module_docstring(module_path) destination_file = os.path.join(destination_dir, file[:-2] + 'md') - with open(destination_file, 'w+') as f_out, \ - open(os.path.join(examples_dir, file), 'r+') as f_in: + with open(destination_file, 'w+', encoding='utf-8') as f_out, \ + open(os.path.join(examples_dir, file), + 'r+', encoding='utf-8') as f_in: f_out.write(docstring + '\n\n') @@ -391,7 +392,7 @@ def generate(sources_dir): readme = read_file(os.path.join(str(keras_dir), 'README.md')) index = read_file(os.path.join(template_dir, 'index.md')) index = index.replace('{{autogenerated}}', readme[readme.find('##'):]) - with open(os.path.join(sources_dir, 'index.md'), 'w') as f: + with open(os.path.join(sources_dir, 'index.md'), 'w', encoding='utf-8') as f: f.write(index) print('Generating docs for Keras %s.' % keras.__version__) @@ -457,7 +458,7 @@ def generate(sources_dir): subdir = os.path.dirname(path) if not os.path.exists(subdir): os.makedirs(subdir) - with open(path, 'w') as f: + with open(path, 'w', encoding='utf-8') as f: f.write(mkdown) shutil.copyfile(os.path.join(str(keras_dir), 'CONTRIBUTING.md'),