Skip to content

Commit

Permalink
Track errors directly on DocGen
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Jan 11, 2024
1 parent 11cf4d7 commit 883a5f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
35 changes: 27 additions & 8 deletions .tools/validation/doc_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@

# 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)
snippet_files: set[str] = field(default_factory=set)
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"

Expand All @@ -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:
Expand All @@ -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,
)
17 changes: 4 additions & 13 deletions .tools/validation/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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.")
Expand Down

0 comments on commit 883a5f6

Please sign in to comment.