提交 9ad5a18f 编写于 作者: F fuzzythecat 提交者: François Chollet

Fix encoding error (#13355)

* Add utf-8 encoding

* Fix PEP8 error

* Fix PEP8 error
上级 04cbccc8
......@@ -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'),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册