Skip to content

Commit dbb39f0

Browse files
committed
fix: package EACS schemas with validator
1 parent 90e4723 commit dbb39f0

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ multi-api = "multi_api_executor.cli:app"
4646
[tool.hatch.build.targets.wheel]
4747
packages = ["src/multi_api_executor"]
4848

49+
[tool.hatch.build.targets.wheel.force-include]
50+
"schemas" = "multi_api_executor/eacs/schemas"
51+
4952
[tool.pytest.ini_options]
5053
addopts = "-ra"
5154
testpaths = ["tests"]

src/multi_api_executor/eacs/validator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import json
55
import re
6+
from importlib.resources import files
67
from pathlib import Path
78
from typing import Any
89

@@ -27,6 +28,15 @@
2728
}
2829

2930

31+
def _load_schema() -> dict[str, Any]:
32+
resource = files("multi_api_executor.eacs").joinpath("schemas/executable-api-cases.schema.json")
33+
if resource.is_file():
34+
return json.loads(resource.read_text(encoding="utf-8"))
35+
return json.loads(
36+
(ROOT / "schemas/executable-api-cases.schema.json").read_text(encoding="utf-8")
37+
)
38+
39+
3040
def _issue(
3141
code: str,
3242
path: str,
@@ -59,9 +69,7 @@ def _walk(value: Any, path: str = "$") -> list[tuple[str, Any]]:
5969

6070

6171
def validate_document(document: Any, *, file: str = "<memory>") -> dict[str, Any]:
62-
schema = json.loads(
63-
(ROOT / "schemas/executable-api-cases.schema.json").read_text(encoding="utf-8")
64-
)
72+
schema = _load_schema()
6573
schema_errors = sorted(
6674
Draft202012Validator(schema).iter_errors(document), key=lambda item: list(item.path)
6775
)

0 commit comments

Comments
 (0)