summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/info.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/info.py')
-rw-r--r--lib/python/qmk/info.py39
1 files changed, 28 insertions, 11 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index b7ee055eef..dbd26153d8 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -50,18 +50,14 @@ def _valid_community_layout(layout):
return (Path('layouts/default') / layout).exists()
-def _validate(keyboard, info_data):
- """Perform various validation on the provided info.json data
- """
- # First validate against the jsonschema
- try:
- validate(info_data, 'qmk.api.keyboard.v1')
+def _get_key_left_position(key):
+ # Special case for ISO enter
+ return key['x'] - 0.25 if key.get('h', 1) == 2 and key.get('w', 1) == 1.25 else key['x']
- except jsonschema.ValidationError as e:
- json_path = '.'.join([str(p) for p in e.absolute_path])
- cli.log.error('Invalid API data: %s: %s: %s', keyboard, json_path, e.message)
- exit(1)
+def _additional_validation(keyboard, info_data):
+ """Non schema checks
+ """
layouts = info_data.get('layouts', {})
layout_aliases = info_data.get('layout_aliases', {})
community_layouts = info_data.get('community_layouts', [])
@@ -73,7 +69,7 @@ def _validate(keyboard, info_data):
# Warn if physical positions are offset (at least one key should be at x=0, and at least one key at y=0)
for layout_name, layout_data in layouts.items():
- offset_x = min([k['x'] for k in layout_data['layout']])
+ offset_x = min([_get_key_left_position(k) for k in layout_data['layout']])
if offset_x > 0:
_log_warning(info_data, f'Layout "{layout_name}" is offset on X axis by {offset_x}')
@@ -103,6 +99,27 @@ def _validate(keyboard, info_data):
if layout_name not in layouts and layout_name not in layout_aliases:
_log_error(info_data, 'Claims to support community layout %s but no %s() macro found' % (layout, layout_name))
+ # keycodes with length > 7 must have short forms for visualisation purposes
+ for decl in info_data.get('keycodes', []):
+ if len(decl["key"]) > 7:
+ if not decl.get("aliases", []):
+ _log_error(info_data, f'Keycode {decl["key"]} has no short form alias')
+
+
+def _validate(keyboard, info_data):
+ """Perform various validation on the provided info.json data
+ """
+ # First validate against the jsonschema
+ try:
+ validate(info_data, 'qmk.api.keyboard.v1')
+
+ _additional_validation(keyboard, info_data)
+
+ except jsonschema.ValidationError as e:
+ json_path = '.'.join([str(p) for p in e.absolute_path])
+ cli.log.error('Invalid API data: %s: %s: %s', keyboard, json_path, e.message)
+ exit(1)
+
def info_json(keyboard):
"""Generate the info.json data for a specific keyboard.