summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/json_schema.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/json_schema.py')
-rw-r--r--lib/python/qmk/json_schema.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/python/qmk/json_schema.py b/lib/python/qmk/json_schema.py
index cbc5bff518..ffc7c6bcd1 100644
--- a/lib/python/qmk/json_schema.py
+++ b/lib/python/qmk/json_schema.py
@@ -2,6 +2,7 @@
"""
import json
from collections.abc import Mapping
+from functools import lru_cache
from pathlib import Path
import hjson
@@ -25,6 +26,7 @@ def json_load(json_file):
exit(1)
+@lru_cache(maxsize=0)
def load_jsonschema(schema_name):
"""Read a jsonschema file from disk.
"""
@@ -39,8 +41,9 @@ def load_jsonschema(schema_name):
return json_load(schema_path)
-def create_validator(schema):
- """Creates a validator for the given schema id.
+@lru_cache(maxsize=0)
+def compile_schema_store():
+ """Compile all our schemas into a schema store.
"""
schema_store = {}
@@ -51,6 +54,14 @@ def create_validator(schema):
continue
schema_store[schema_data['$id']] = schema_data
+ return schema_store
+
+
+@lru_cache(maxsize=0)
+def create_validator(schema):
+ """Creates a validator for the given schema id.
+ """
+ schema_store = compile_schema_store()
resolver = jsonschema.RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store)
return jsonschema.Draft7Validator(schema_store[schema], resolver=resolver).validate