aboutsummaryrefslogtreecommitdiff
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.py51
1 files changed, 47 insertions, 4 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index 815b851474..ffc9d57d68 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -58,8 +58,13 @@ def _get_key_left_position(key):
def _find_invalid_encoder_index(info_data):
"""Perform additional validation of encoders
"""
- enc_count = len(info_data.get('encoder', {}).get('rotary', []))
- enc_count += len(info_data.get('split', {}).get('encoder', {}).get('right', {}).get('rotary', []))
+ enc_left = info_data.get('encoder', {}).get('rotary', [])
+ enc_right = []
+
+ if info_data.get('split', {}).get('enabled', False):
+ enc_right = info_data.get('split', {}).get('encoder', {}).get('right', {}).get('rotary', enc_left)
+
+ enc_count = len(enc_left) + len(enc_right)
ret = []
layouts = info_data.get('layouts', {})
@@ -78,6 +83,25 @@ def _find_invalid_encoder_index(info_data):
return ret
+def _validate_build_target(keyboard, info_data):
+ """Non schema checks
+ """
+ keyboard_json_path = Path('keyboards') / keyboard / 'keyboard.json'
+ config_files = find_info_json(keyboard)
+
+ # keyboard.json can only exist at the deepest part of the tree
+ keyboard_json_count = 0
+ for info_file in config_files:
+ if info_file.name == 'keyboard.json':
+ keyboard_json_count += 1
+ if info_file != keyboard_json_path:
+ _log_error(info_data, f'Invalid keyboard.json location detected: {info_file}.')
+
+ # Moving forward keyboard.json should be used as a build target
+ if keyboard_json_count == 0:
+ _log_warning(info_data, 'Build marker "keyboard.json" not found.')
+
+
def _validate_layouts(keyboard, info_data): # noqa C901
"""Non schema checks
"""
@@ -107,6 +131,15 @@ def _validate_layouts(keyboard, info_data): # noqa C901
if col >= col_num:
_log_error(info_data, f'{layout_name}: Matrix column for key {index} ({key_name}) is {col} but must be less than {col_num}')
+ # Reject duplicate matrix locations
+ for layout_name, layout_data in layouts.items():
+ seen = set()
+ for index, key_data in enumerate(layout_data['layout']):
+ key = f"{key_data['matrix']}"
+ if key in seen:
+ _log_error(info_data, f'{layout_name}: Matrix location for key {index} is not unique {key_data}')
+ seen.add(key)
+
# 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([_get_key_left_position(k) for k in layout_data['layout']])
@@ -167,6 +200,7 @@ def _validate(keyboard, info_data):
validate(info_data, 'qmk.api.keyboard.v1')
# Additional validation
+ _validate_build_target(keyboard, info_data)
_validate_layouts(keyboard, info_data)
_validate_keycodes(keyboard, info_data)
_validate_encoders(keyboard, info_data)
@@ -375,6 +409,12 @@ def _extract_encoders(info_data, config_c):
info_data['encoder']['rotary'] = encoders
+ # TODO: some logic still assumes ENCODER_ENABLED would partially create encoder dict
+ if info_data.get('features', {}).get('encoder', False):
+ if 'encoder' not in info_data:
+ info_data['encoder'] = {}
+ info_data['encoder']['enabled'] = True
+
def _extract_split_encoders(info_data, config_c):
"""Populate data about split encoder pins
@@ -868,7 +908,9 @@ def unknown_processor_rules(info_data, rules):
def merge_info_jsons(keyboard, info_data):
"""Return a merged copy of all the info.json files for a keyboard.
"""
- for info_file in find_info_json(keyboard):
+ config_files = find_info_json(keyboard)
+
+ for info_file in config_files:
# Load and validate the JSON data
new_info_data = json_load(info_file)
@@ -926,7 +968,7 @@ def find_info_json(keyboard):
base_path = Path('keyboards')
keyboard_path = base_path / keyboard
keyboard_parent = keyboard_path.parent
- info_jsons = [keyboard_path / 'info.json']
+ info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json']
# Add DEFAULT_FOLDER before parents, if present
rules = rules_mk(keyboard)
@@ -938,6 +980,7 @@ def find_info_json(keyboard):
if keyboard_parent == base_path:
break
info_jsons.append(keyboard_parent / 'info.json')
+ info_jsons.append(keyboard_parent / 'keyboard.json')
keyboard_parent = keyboard_parent.parent
# Return a list of the info.json files that actually exist