From 73083581a41740dc67359d65e55530114863bd20 Mon Sep 17 00:00:00 2001 From: Bram Vanroy Date: Mon, 13 Jun 2022 14:05:45 +0200 Subject: [PATCH] explicitly set utf8 for Windows (#17664) --- utils/check_repo.py | 2 +- utils/custom_init_isort.py | 4 ++-- utils/notification_service_doc_tests.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/check_repo.py b/utils/check_repo.py index 4d420cac66..f17a425f19 100644 --- a/utils/check_repo.py +++ b/utils/check_repo.py @@ -725,7 +725,7 @@ def check_docstrings_are_in_md(): """Check all docstrings are in md""" files_with_rst = [] for file in Path(PATH_TO_TRANSFORMERS).glob("**/*.py"): - with open(file, "r") as f: + with open(file, encoding="utf-8") as f: code = f.read() docstrings = code.split('"""') diff --git a/utils/custom_init_isort.py b/utils/custom_init_isort.py index 456ff4aedc..375cdb662f 100644 --- a/utils/custom_init_isort.py +++ b/utils/custom_init_isort.py @@ -167,7 +167,7 @@ def sort_imports(file, check_only=True): """ Sort `_import_structure` imports in `file`, `check_only` determines if we only check or overwrite. """ - with open(file, "r") as f: + with open(file, encoding="utf-8") as f: code = f.read() if "_import_structure" not in code: @@ -227,7 +227,7 @@ def sort_imports(file, check_only=True): return True else: print(f"Overwriting {file}.") - with open(file, "w") as f: + with open(file, "w", encoding="utf-8") as f: f.write("\n".join(main_blocks)) diff --git a/utils/notification_service_doc_tests.py b/utils/notification_service_doc_tests.py index 72c6be2ce0..d02b08b605 100644 --- a/utils/notification_service_doc_tests.py +++ b/utils/notification_service_doc_tests.py @@ -289,7 +289,7 @@ def retrieve_artifact(name: str): files = os.listdir(name) for file in files: try: - with open(os.path.join(name, file)) as f: + with open(os.path.join(name, file), encoding="utf-8") as f: _artifact[file.split(".")[0]] = f.read() except UnicodeDecodeError as e: raise ValueError(f"Could not open {os.path.join(name, file)}.") from e