Loading testing/xml/lint_xml.py +28 −8 Changes for testing/xml/lint_xml.py: 28 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -14,9 +14,11 @@ colorama.init() ignore_paths = [Path(x) for x in ["testing/deps"]] # TODO - get rid of these exceptions when we can ignore_files = [str(Path("104000/schema/TS_104_000.xsd")), ignore_files = [ str(Path("104000/schema/TS_104_000.xsd")), str(Path("103221-2/TS_103_221_02_Configuration.xsd")), str(Path("103707/TS_103_707.xsd"))] str(Path("103707/TS_103_707.xsd")), ] XS = "{http://www.w3.org/2001/XMLSchema}" etree_parser = etree.XMLParser( Loading @@ -36,22 +38,29 @@ def print_colorized_diff_line(line: str): else: return line def run_linter(file: Path) -> str: completed = subprocess.run( # TODO - get the spacing from the editorconfig, rather than hardcoding it ["xmllint", "--format", str(file)], capture_output=True, text=True, encoding="utf8", env={"XMLLINT_INDENT": " "} ["xmllint", "--format", str(file)], capture_output=True, text=True, encoding="utf8", env={"XMLLINT_INDENT": " "}, ) if completed.returncode != 0: raise RuntimeError(f"xmllint failed with error code {completed.returncode}") linted_xml = completed.stdout return linted_xml def get_errors(file: Path) -> str: errors = get_linting_errors(file) errors += get_type_errors(file) return errors def get_linting_errors(file: Path) -> str: linted_xml = run_linter(file) orig_xml = file.read_text(encoding="utf8") Loading @@ -61,6 +70,7 @@ def get_linting_errors(file: Path) -> str: else: return "\n".join([print_colorized_diff_line(d) for d in diff]) def get_type_errors(file: Path) -> str: with open(file) as f: lines = f.read().splitlines() Loading Loading @@ -91,6 +101,7 @@ def get_type_errors(file: Path) -> str: return "" def prettify_file(file: Path): linted_xml = run_linter(file) Loading @@ -106,8 +117,17 @@ def prettify_file(file: Path): if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", help="Specific file to lint (use - for stdin). If omitted, lint all XML files in the repo.") parser.add_argument("-p", "--prettify", action="store_true", help="Rewrite the file to no longer offend the linter") parser.add_argument( "-i", "--input", help="Specific file to lint (use - for stdin). If omitted, lint all XML files in the repo.", ) parser.add_argument( "-p", "--prettify", action="store_true", help="Rewrite the file to no longer offend the linter", ) args = parser.parse_args() if args.prettify: Loading Loading @@ -139,8 +159,9 @@ if __name__ == "__main__": error_files = {} for f in files: if (len(list(set(f.parents) & set(ignore_paths))) > 0) or\ (str(f) in ignore_files): if (len(list(set(f.parents) & set(ignore_paths))) > 0) or ( str(f) in ignore_files ): print(f"(Ignoring {f})") continue new_errors = get_errors(f) Loading @@ -151,7 +172,6 @@ if __name__ == "__main__": else: print(f"✅ {str(f)}") for k, v in error_files.items(): print("───────────────────────────────────────────────────────────────────") print(f"❌ {k}") Loading Loading
testing/xml/lint_xml.py +28 −8 Changes for testing/xml/lint_xml.py: 28 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -14,9 +14,11 @@ colorama.init() ignore_paths = [Path(x) for x in ["testing/deps"]] # TODO - get rid of these exceptions when we can ignore_files = [str(Path("104000/schema/TS_104_000.xsd")), ignore_files = [ str(Path("104000/schema/TS_104_000.xsd")), str(Path("103221-2/TS_103_221_02_Configuration.xsd")), str(Path("103707/TS_103_707.xsd"))] str(Path("103707/TS_103_707.xsd")), ] XS = "{http://www.w3.org/2001/XMLSchema}" etree_parser = etree.XMLParser( Loading @@ -36,22 +38,29 @@ def print_colorized_diff_line(line: str): else: return line def run_linter(file: Path) -> str: completed = subprocess.run( # TODO - get the spacing from the editorconfig, rather than hardcoding it ["xmllint", "--format", str(file)], capture_output=True, text=True, encoding="utf8", env={"XMLLINT_INDENT": " "} ["xmllint", "--format", str(file)], capture_output=True, text=True, encoding="utf8", env={"XMLLINT_INDENT": " "}, ) if completed.returncode != 0: raise RuntimeError(f"xmllint failed with error code {completed.returncode}") linted_xml = completed.stdout return linted_xml def get_errors(file: Path) -> str: errors = get_linting_errors(file) errors += get_type_errors(file) return errors def get_linting_errors(file: Path) -> str: linted_xml = run_linter(file) orig_xml = file.read_text(encoding="utf8") Loading @@ -61,6 +70,7 @@ def get_linting_errors(file: Path) -> str: else: return "\n".join([print_colorized_diff_line(d) for d in diff]) def get_type_errors(file: Path) -> str: with open(file) as f: lines = f.read().splitlines() Loading Loading @@ -91,6 +101,7 @@ def get_type_errors(file: Path) -> str: return "" def prettify_file(file: Path): linted_xml = run_linter(file) Loading @@ -106,8 +117,17 @@ def prettify_file(file: Path): if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", help="Specific file to lint (use - for stdin). If omitted, lint all XML files in the repo.") parser.add_argument("-p", "--prettify", action="store_true", help="Rewrite the file to no longer offend the linter") parser.add_argument( "-i", "--input", help="Specific file to lint (use - for stdin). If omitted, lint all XML files in the repo.", ) parser.add_argument( "-p", "--prettify", action="store_true", help="Rewrite the file to no longer offend the linter", ) args = parser.parse_args() if args.prettify: Loading Loading @@ -139,8 +159,9 @@ if __name__ == "__main__": error_files = {} for f in files: if (len(list(set(f.parents) & set(ignore_paths))) > 0) or\ (str(f) in ignore_files): if (len(list(set(f.parents) & set(ignore_paths))) > 0) or ( str(f) in ignore_files ): print(f"(Ignoring {f})") continue new_errors = get_errors(f) Loading @@ -151,7 +172,6 @@ if __name__ == "__main__": else: print(f"✅ {str(f)}") for k, v in error_files.items(): print("───────────────────────────────────────────────────────────────────") print(f"❌ {k}") Loading