In catalog_linter, lint all toml files (graveyard wishlist etc). This is actually done in CI.
This commit is contained in:
parent
cc0381871d
commit
88aa6490c5
1 changed files with 25 additions and 17 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from typing import Any, Dict, Generator, List, Tuple
|
from typing import Any, Dict, Generator, List, Tuple
|
||||||
|
|
||||||
|
@ -16,16 +17,27 @@ from appslib.utils import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_schema() -> Generator[str, None, None]:
|
def validate_schema(data: dict, schema_path: Path) -> Generator[str, None, None]:
|
||||||
with open(
|
schema = json.load(schema_path.open("r", encoding="utf-8"))
|
||||||
REPO_APPS_ROOT / "schemas" / "apps.toml.schema.json", encoding="utf-8"
|
validator = jsonschema.Draft202012Validator(schema)
|
||||||
) as file:
|
for error in validator.iter_errors(data):
|
||||||
apps_catalog_schema = json.load(file)
|
|
||||||
validator = jsonschema.Draft202012Validator(apps_catalog_schema)
|
|
||||||
for error in validator.iter_errors(get_catalog()):
|
|
||||||
yield f"at .{'.'.join(error.path)}: {error.message}"
|
yield f"at .{'.'.join(error.path)}: {error.message}"
|
||||||
|
|
||||||
|
|
||||||
|
def validate_schema_pretty(data: dict, name: str) -> bool:
|
||||||
|
schema_path = REPO_APPS_ROOT / "schemas" / f"{name}.schema.json"
|
||||||
|
has_errors = False
|
||||||
|
schema_errors = list(validate_schema(data, schema_path))
|
||||||
|
if schema_errors:
|
||||||
|
has_errors = True
|
||||||
|
print(f"Error while validating {name} against schema:")
|
||||||
|
for error in schema_errors:
|
||||||
|
print(f" - {error}")
|
||||||
|
if schema_errors:
|
||||||
|
print()
|
||||||
|
return has_errors
|
||||||
|
|
||||||
|
|
||||||
def check_app(
|
def check_app(
|
||||||
app: str, infos: Dict[str, Any]
|
app: str, infos: Dict[str, Any]
|
||||||
) -> Generator[Tuple[str, bool], None, None]:
|
) -> Generator[Tuple[str, bool], None, None]:
|
||||||
|
@ -88,14 +100,11 @@ def check_all_apps() -> Generator[Tuple[str, List[Tuple[str, bool]]], None, None
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
has_errors = False
|
has_errors = False
|
||||||
|
|
||||||
schema_errors = list(validate_schema())
|
has_errors |= validate_schema_pretty(get_antifeatures(), "antifeatures.toml")
|
||||||
if schema_errors:
|
has_errors |= validate_schema_pretty(get_catalog(), "apps.toml")
|
||||||
has_errors = True
|
has_errors |= validate_schema_pretty(get_categories(), "categories.toml")
|
||||||
print("Error while validating catalog against schema:")
|
has_errors |= validate_schema_pretty(get_graveyard(), "graveyard.toml")
|
||||||
for error in schema_errors:
|
has_errors |= validate_schema_pretty(get_wishlist(), "wishlist.toml")
|
||||||
print(f" - {error}")
|
|
||||||
if schema_errors:
|
|
||||||
print()
|
|
||||||
|
|
||||||
for app, errors in check_all_apps():
|
for app, errors in check_all_apps():
|
||||||
print(f"{app}:")
|
print(f"{app}:")
|
||||||
|
@ -105,8 +114,7 @@ def main() -> None:
|
||||||
level = "error" if is_fatal else "warning"
|
level = "error" if is_fatal else "warning"
|
||||||
print(f" - {level}: {error}")
|
print(f" - {level}: {error}")
|
||||||
|
|
||||||
if has_errors:
|
sys.exit(has_errors)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue