Use explicit UTF-8 encoding

This commit is contained in:
Wiktor Niesiobędzki 2024-04-02 12:13:10 +00:00 committed by Wiktor Niesiobędzki
parent fb4a661f54
commit bc5f4c3969
1 changed files with 5 additions and 5 deletions

View File

@ -168,7 +168,7 @@ def parse_files(basepath, exclude_files=None):
if shortname in exclude_files: if shortname in exclude_files:
continue continue
try: try:
with open(name) as file: with open(name, encoding='utf-8') as file:
body = file.read() body = file.read()
except (IOError, OSError) as e: except (IOError, OSError) as e:
raise SystemExit(f'Cannot read file {name}: {e}') raise SystemExit(f'Cannot read file {name}: {e}')
@ -192,7 +192,7 @@ def parse_outputs(basepath, exclude_files=None):
if shortname in exclude_files: if shortname in exclude_files:
continue continue
try: try:
with open(name) as file: with open(name, encoding='utf-8') as file:
body = file.read() body = file.read()
except (IOError, OSError) as e: except (IOError, OSError) as e:
raise SystemExit(f'Cannot open outputs file {shortname}.') raise SystemExit(f'Cannot open outputs file {shortname}.')
@ -215,7 +215,7 @@ def parse_variables(basepath, exclude_files=None):
if shortname in exclude_files: if shortname in exclude_files:
continue continue
try: try:
with open(name) as file: with open(name, encoding='utf-8') as file:
body = file.read() body = file.read()
except (IOError, OSError) as e: except (IOError, OSError) as e:
raise SystemExit(f'Cannot open variables file {shortname}.') raise SystemExit(f'Cannot open variables file {shortname}.')
@ -430,7 +430,7 @@ def create_tfref(module_path, files=False, show_extra=False, exclude_files=None,
def get_readme(readme_path): def get_readme(readme_path):
'Open and return README.md in module.' 'Open and return README.md in module.'
try: try:
return open(readme_path).read() return open(readme_path, "r", encoding="utf-8").read()
except (IOError, OSError) as e: except (IOError, OSError) as e:
raise SystemExit(f'Error opening README {readme_path}: {e}') raise SystemExit(f'Error opening README {readme_path}: {e}')
@ -486,7 +486,7 @@ def main(module_path=None, exclude_file=None, files=False, replace=True,
readme = render_toc(readme, toc) readme = render_toc(readme, toc)
if replace: if replace:
try: try:
with open(readme_path, 'w') as f: with open(readme_path, 'w', encoding='utf-8') as f:
f.write(readme) f.write(readme)
except (IOError, OSError) as e: except (IOError, OSError) as e:
raise SystemExit(f'Error replacing README {readme_path}: {e}') raise SystemExit(f'Error replacing README {readme_path}: {e}')