diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 41795086df98..4472e465dffe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,7 +43,7 @@ repos: - id: check-yaml exclude: ^\.clang-format$ - id: end-of-file-fixer - exclude: ^.*UTF-8-BOM.txt$ + exclude: ^.*(UTF-8-BOM\.txt|\.ts)$ - id: mixed-line-ending - id: trailing-whitespace exclude: \.(c|cc|cxx|cpp|ts|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|js|m|mm|proto|vert)$ @@ -178,6 +178,7 @@ repos: stages: - commit - manual + require_serial: true language: python additional_dependencies: - lxml==4.9.3 diff --git a/tools/ts_source_copy_check.py b/tools/ts_source_copy_check.py index bec83faefcc4..25be21bd61db 100755 --- a/tools/ts_source_copy_check.py +++ b/tools/ts_source_copy_check.py @@ -21,35 +21,57 @@ def is_untranstaled_allowed(source_text, language): if os.path.exists(ALLOW_LIST_PATH): parser = etree.XMLParser(recover=True) - tree = etree.parse(ALLOW_LIST_PATH, parser) + try: + tree = etree.parse(ALLOW_LIST_PATH, parser) + except Exception as e: + print("XML parsing failed:") + print(e) + raise e root = tree.getroot() else: return False - for message in root.findall("message"): - if message.find("source").text == source_text: - if message.find("allow_all_languages").text == "true": - return True - languages_elem = message.find("allowed_languages") - if languages_elem is None: - return False - allowed_languages = { - lang.text for lang in languages_elem.findall("language") - } - if language in allowed_languages: - return True + try: + for message in root.findall("message"): + if message.find("source").text == source_text: + if message.find("allow_all_languages").text == "true": + return True + languages_elem = message.find("allowed_languages") + if languages_elem is None: + return False + allowed_languages = { + lang.text for lang in languages_elem.findall("language") + } + if language in allowed_languages: + return True + + except Exception as e: + print(f"Parsing failed at {message.base}:{message.sourceline}") + print(e) + raise e + return False def add_to_allow_list(source_text, language): if os.path.exists(PROPOSED_ALLOW_LIST_PATH): parser = etree.XMLParser(recover=True) - tree = etree.parse(PROPOSED_ALLOW_LIST_PATH, parser) + try: + tree = etree.parse(PROPOSED_ALLOW_LIST_PATH, parser) + except Exception as e: + print("XML parsing failed:") + print(e) + raise e root = tree.getroot() else: if os.path.exists(ALLOW_LIST_PATH): parser = etree.XMLParser(recover=True) - tree = etree.parse(ALLOW_LIST_PATH, parser) + try: + tree = etree.parse(ALLOW_LIST_PATH, parser) + except Exception as e: + print("XML parsing failed:") + print(e) + return root = tree.getroot() else: root = etree.Element("allow_list") @@ -57,10 +79,15 @@ def add_to_allow_list(source_text, language): # Check if the message already exists existing_message = None - for message in root.findall("message"): - if message.find("source").text == source_text: - existing_message = message - break + try: + for message in root.findall("message"): + if message.find("source").text == source_text: + existing_message = message + break + except Exception as e: + print(f"Parsing failed at {message.base}:{message.sourceline}") + print(e) + raise e if existing_message is not None: allow_all_languages = ( @@ -110,7 +137,14 @@ def check_copied_source_on_lines(rootdir, file_to_format, stylepath=None): return False parser = etree.XMLParser(recover=True) - tree = etree.parse(filename, parser) + + try: + tree = etree.parse(filename, parser) + except Exception as e: + print("XML parsing failed:") + print(e) + return False + root = tree.getroot() found = False