diff options
Diffstat (limited to 'lib/python/qmk/json_schema.py')
-rw-r--r-- | lib/python/qmk/json_schema.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/python/qmk/json_schema.py b/lib/python/qmk/json_schema.py index cbc5bff51..ffc7c6bcd 100644 --- a/lib/python/qmk/json_schema.py +++ b/lib/python/qmk/json_schema.py | |||
@@ -2,6 +2,7 @@ | |||
2 | """ | 2 | """ |
3 | import json | 3 | import json |
4 | from collections.abc import Mapping | 4 | from collections.abc import Mapping |
5 | from functools import lru_cache | ||
5 | from pathlib import Path | 6 | from pathlib import Path |
6 | 7 | ||
7 | import hjson | 8 | import hjson |
@@ -25,6 +26,7 @@ def json_load(json_file): | |||
25 | exit(1) | 26 | exit(1) |
26 | 27 | ||
27 | 28 | ||
29 | @lru_cache(maxsize=0) | ||
28 | def load_jsonschema(schema_name): | 30 | def load_jsonschema(schema_name): |
29 | """Read a jsonschema file from disk. | 31 | """Read a jsonschema file from disk. |
30 | """ | 32 | """ |
@@ -39,8 +41,9 @@ def load_jsonschema(schema_name): | |||
39 | return json_load(schema_path) | 41 | return json_load(schema_path) |
40 | 42 | ||
41 | 43 | ||
42 | def create_validator(schema): | 44 | @lru_cache(maxsize=0) |
43 | """Creates a validator for the given schema id. | 45 | def compile_schema_store(): |
46 | """Compile all our schemas into a schema store. | ||
44 | """ | 47 | """ |
45 | schema_store = {} | 48 | schema_store = {} |
46 | 49 | ||
@@ -51,6 +54,14 @@ def create_validator(schema): | |||
51 | continue | 54 | continue |
52 | schema_store[schema_data['$id']] = schema_data | 55 | schema_store[schema_data['$id']] = schema_data |
53 | 56 | ||
57 | return schema_store | ||
58 | |||
59 | |||
60 | @lru_cache(maxsize=0) | ||
61 | def create_validator(schema): | ||
62 | """Creates a validator for the given schema id. | ||
63 | """ | ||
64 | schema_store = compile_schema_store() | ||
54 | resolver = jsonschema.RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store) | 65 | resolver = jsonschema.RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store) |
55 | 66 | ||
56 | return jsonschema.Draft7Validator(schema_store[schema], resolver=resolver).validate | 67 | return jsonschema.Draft7Validator(schema_store[schema], resolver=resolver).validate |