Cache xap specs

This commit is contained in:
zvecr 2022-05-10 03:48:48 +01:00
parent ea850f1380
commit f9f0d84eb0
2 changed files with 13 additions and 10 deletions

View file

@ -10,7 +10,7 @@ from milc import cli
from qmk.xap.common import get_xap_keycodes
KEYCODE_MAP = get_xap_keycodes('0.2.0')
KEYCODE_MAP = get_xap_keycodes('latest')
def _is_xap_usage(x):

View file

@ -8,6 +8,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
from qmk.constants import QMK_FIRMWARE
from qmk.json_schema import json_load
from qmk.decorators import lru_cache
def _get_jinja2_env(data_templates_xap_subdir: str):
@ -74,19 +75,14 @@ def update_xap_definitions(original, new):
return _merge_ordered_dicts([original, new])
def latest_xap_defs():
"""Gets the latest version of the XAP definitions.
"""
definitions = [hjson.load(file.open(encoding='utf-8')) for file in get_xap_definition_files()]
return _merge_ordered_dicts(definitions)
@lru_cache(timeout=5)
def get_xap_defs(version):
"""Gets the required version of the XAP definitions.
"""
files = get_xap_definition_files()
# Slice off anything newer than specified version
if version != 'latest':
index = [idx for idx, s in enumerate(files) if version in str(s)][0]
files = files[:(index + 1)]
@ -94,6 +90,13 @@ def get_xap_defs(version):
return _merge_ordered_dicts(definitions)
def latest_xap_defs():
"""Gets the latest version of the XAP definitions.
"""
return get_xap_defs('latest')
@lru_cache(timeout=5)
def get_xap_keycodes(xap_version):
"""Gets keycode data for the required version of the XAP definitions.
"""