diff --git a/lib/python/qmk/cli/xap/xap.py b/lib/python/qmk/cli/xap/xap.py index a90625e748..e0af627ef3 100644 --- a/lib/python/qmk/cli/xap/xap.py +++ b/lib/python/qmk/cli/xap/xap.py @@ -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): diff --git a/lib/python/qmk/xap/common.py b/lib/python/qmk/xap/common.py index 1a39682e09..8d68de3fab 100755 --- a/lib/python/qmk/xap/common.py +++ b/lib/python/qmk/xap/common.py @@ -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,26 +75,28 @@ 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 - index = [idx for idx, s in enumerate(files) if version in str(s)][0] - files = files[:(index + 1)] + if version != 'latest': + index = [idx for idx, s in enumerate(files) if version in str(s)][0] + files = files[:(index + 1)] definitions = [hjson.load(file.open(encoding='utf-8')) for file in files] 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. """