From 883a5f6f5d03fa31f7ff2b05eec700f26142e10f Mon Sep 17 00:00:00 2001 From: David Souther Date: Thu, 11 Jan 2024 11:05:10 -0500 Subject: [PATCH] Track errors directly on DocGen --- .tools/validation/doc_gen.py | 35 +++++++++++++++++++++++++++-------- .tools/validation/validate.py | 17 ++++------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/.tools/validation/doc_gen.py b/.tools/validation/doc_gen.py index 310a257530d..5062721b2ef 100644 --- a/.tools/validation/doc_gen.py +++ b/.tools/validation/doc_gen.py @@ -9,16 +9,19 @@ # from os import glob -from file_utils import get_files -from metadata_errors import MetadataErrors from metadata import Example, parse as parse_examples +from metadata_errors import MetadataErrors +from metadata_validator import validate_metadata +from project_validator import check_files, verify_sample_files from sdks import Sdk, parse as parse_sdks from services import Service, parse as parse_services -from snippets import Snippet, collect_snippets +from snippets import Snippet, collect_snippets, validate_snippets @dataclass class DocGen: + root_path: Path + errors: MetadataErrors sdks: dict[str, Sdk] = field(default_factory=dict) services: dict[str, Service] = field(default_factory=dict) snippets: dict[str, Snippet] = field(default_factory=dict) @@ -26,9 +29,7 @@ class DocGen: examples: list[Example] = field(default_factory=list) @classmethod - def from_root( - cls, root: Path, snippets_root: Path | None = None - ) -> tuple[Self, MetadataErrors]: + def from_root(cls, root: Path, snippets_root: Path | None = None) -> Self: errors = MetadataErrors() metadata = root / ".doc_gen/metadata" @@ -46,7 +47,13 @@ def from_root( snippets_root = root.parent.parent snippets, errs = collect_snippets(snippets_root) - doc_gen = cls(sdks=sdks, services=services, snippets=snippets) + doc_gen = cls( + sdks=sdks, + services=services, + snippets=snippets, + errors=errors, + root_path=root, + ) for path in metadata.glob("*_metadata.yaml"): with open(path) as file: @@ -56,4 +63,16 @@ def from_root( doc_gen.examples.extend(ex) errors.extend(errs) - return doc_gen, errors + return doc_gen + + def validate(self): + check_files(self.root_path, self.errors) + verify_sample_files(self.root_path, self.errors) + validate_metadata(self.root_path, self.errors) + validate_snippets( + self.examples, + self.snippets, + self.snippet_files, + self.errors, + self.root_path, + ) diff --git a/.tools/validation/validate.py b/.tools/validation/validate.py index 88e3cce7e95..aba16470928 100755 --- a/.tools/validation/validate.py +++ b/.tools/validation/validate.py @@ -6,9 +6,6 @@ from sys import exit from doc_gen import DocGen -from metadata_validator import validate_metadata -from project_validator import check_files, verify_sample_files -from snippets import validate_snippets def main(): @@ -21,18 +18,12 @@ def main(): args = parser.parse_args() root_path = Path(args.root).resolve() - doc_gen, errors = DocGen.from_root(root=root_path, snippets_root=root_path) + doc_gen = DocGen.from_root(root=root_path, snippets_root=root_path) + doc_gen.validate() - check_files(root_path, errors) - verify_sample_files(root_path, errors) - validate_metadata(root_path, errors) - validate_snippets( - doc_gen.examples, doc_gen.snippets, doc_gen.snippet_files, errors, root_path - ) - - error_count = len(errors) + error_count = len(doc_gen.errors) if error_count > 0: - print(f"{errors}") + print(f"{doc_gen.errors}") print(f"{error_count} errors found, please fix them.") else: print("All checks passed, you are cleared to check in.")