From 2a889553efea47fb6f28e48f3251503b2314236b Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Tue, 26 May 2020 10:04:19 +0200 Subject: [PATCH] Finding cross-provider dependencies fails when encoding wrong (#9012) This forces encoding of read python files to utf-8 --- tests/build_provider_packages_dependencies.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/build_provider_packages_dependencies.py b/tests/build_provider_packages_dependencies.py index a4e7688f520bb..884e3bcd0a585 100644 --- a/tests/build_provider_packages_dependencies.py +++ b/tests/build_provider_packages_dependencies.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +import io import json import os import sys @@ -153,8 +154,12 @@ def get_imports_from_file(file_name: str) -> List[str]: :param file_name: name of the file :return: list of import names """ - with open(file_name) as f: - root = parse(f.read(), file_name) + try: + with io.open(file_name, "rt", encoding="utf-8") as f: + root = parse(f.read(), file_name) + except Exception: + print(f"Error when opening file {file_name}", file=sys.stderr) + raise visitor = ImportFinder(file_name) visitor.visit(root) return visitor.imports @@ -243,7 +248,7 @@ def insert_documentation(deps_dict: Dict[str, List[str]], res: List[str]): print(f"Written provider dependencies to the file {provider_dependencies_file_name}") print() if documentation_file_name: - with open(documentation_file_name, "r") as documentation_file: + with io.open(documentation_file_name, "r", encoding="utf-8") as documentation_file: text = documentation_file.readlines() replacing = False result: List[str] = [] @@ -256,7 +261,7 @@ def insert_documentation(deps_dict: Dict[str, List[str]], res: List[str]): replacing = False if not replacing: result.append(line) - with open(documentation_file_name, "w") as documentation_file: + with io.open(documentation_file_name, "w", encoding="utf-8") as documentation_file: documentation_file.write("".join(result)) print() print(f"Written package extras to the file {documentation_file_name}")