summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli')
-rwxr-xr-xlib/python/qmk/cli/format/json.py4
-rwxr-xr-xlib/python/qmk/cli/generate/config_h.py2
-rwxr-xr-xlib/python/qmk/cli/generate/keyboard_c.py25
-rw-r--r--lib/python/qmk/cli/lint.py15
-rw-r--r--lib/python/qmk/cli/migrate.py5
5 files changed, 38 insertions, 13 deletions
diff --git a/lib/python/qmk/cli/format/json.py b/lib/python/qmk/cli/format/json.py
index 283513254c..87a3837d10 100755
--- a/lib/python/qmk/cli/format/json.py
+++ b/lib/python/qmk/cli/format/json.py
@@ -92,8 +92,8 @@ def format_json(cli):
output = json.dumps(json_data, cls=json_encoder, sort_keys=True)
if cli.args.inplace:
- with open(cli.args.json_file, 'w+', encoding='utf-8') as outfile:
- outfile.write(output)
+ with open(cli.args.json_file, 'w+', encoding='utf-8', newline='\n') as outfile:
+ outfile.write(output + '\n')
# Display the results if print was set
# We don't operate in-place by default, so also display to stdout
diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py
index 00fb1d9585..fc681300a3 100755
--- a/lib/python/qmk/cli/generate/config_h.py
+++ b/lib/python/qmk/cli/generate/config_h.py
@@ -108,6 +108,8 @@ def generate_config_items(kb_info_json, config_h_lines):
elif key_type.startswith('array'):
config_h_lines.append(generate_define(config_key, f'{{ {", ".join(map(str, config_value))} }}'))
elif key_type == 'bool':
+ config_h_lines.append(generate_define(config_key, 'true' if config_value else 'false'))
+ elif key_type == 'flag':
if config_value:
config_h_lines.append(generate_define(config_key))
elif key_type == 'mapping':
diff --git a/lib/python/qmk/cli/generate/keyboard_c.py b/lib/python/qmk/cli/generate/keyboard_c.py
index f010341613..5a6c967486 100755
--- a/lib/python/qmk/cli/generate/keyboard_c.py
+++ b/lib/python/qmk/cli/generate/keyboard_c.py
@@ -9,21 +9,25 @@ from qmk.path import normpath
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
-def _gen_led_config(info_data):
+def _gen_led_configs(info_data):
+ lines = []
+
+ if 'layout' in info_data.get('rgb_matrix', {}):
+ lines.extend(_gen_led_config(info_data, 'rgb_matrix'))
+
+ if 'layout' in info_data.get('led_matrix', {}):
+ lines.extend(_gen_led_config(info_data, 'led_matrix'))
+
+ return lines
+
+
+def _gen_led_config(info_data, config_type):
"""Convert info.json content to g_led_config
"""
cols = info_data['matrix_size']['cols']
rows = info_data['matrix_size']['rows']
- config_type = None
- if 'layout' in info_data.get('rgb_matrix', {}):
- config_type = 'rgb_matrix'
- elif 'layout' in info_data.get('led_matrix', {}):
- config_type = 'led_matrix'
-
lines = []
- if not config_type:
- return lines
matrix = [['NO_LED'] * cols for _ in range(rows)]
pos = []
@@ -53,6 +57,7 @@ def _gen_led_config(info_data):
lines.append(f' {{ {", ".join(flags)} }},')
lines.append('};')
lines.append('#endif')
+ lines.append('')
return lines
@@ -98,7 +103,7 @@ def generate_keyboard_c(cli):
# Build the layouts.h file.
keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#include QMK_KEYBOARD_H', '']
- keyboard_h_lines.extend(_gen_led_config(kb_info_json))
+ keyboard_h_lines.extend(_gen_led_configs(kb_info_json))
keyboard_h_lines.extend(_gen_matrix_mask(kb_info_json))
# Show the results
diff --git a/lib/python/qmk/cli/lint.py b/lib/python/qmk/cli/lint.py
index a7c85b5643..7ebb0cf9c4 100644
--- a/lib/python/qmk/cli/lint.py
+++ b/lib/python/qmk/cli/lint.py
@@ -13,6 +13,7 @@ from qmk.git import git_get_ignored_files
from qmk.c_parse import c_source_files
CHIBIOS_CONF_CHECKS = ['chconf.h', 'halconf.h', 'mcuconf.h', 'board.h']
+INVALID_KB_FEATURES = set(['encoder_map', 'dip_switch_map', 'combo', 'tap_dance', 'via'])
def _list_defaultish_keymaps(kb):
@@ -69,6 +70,17 @@ def _handle_json_errors(kb, info):
return ok
+def _handle_invalid_features(kb, info):
+ """Check for features that should never be enabled at the keyboard level
+ """
+ ok = True
+ features = set(info.get('features', []))
+ for found in features & INVALID_KB_FEATURES:
+ ok = False
+ cli.log.error(f'{kb}: Invalid keyboard level feature detected - {found}')
+ return ok
+
+
def _chibios_conf_includenext_check(target):
"""Check the ChibiOS conf.h for the correct inclusion of the next conf.h
"""
@@ -154,6 +166,9 @@ def keyboard_check(kb):
ok = False
# Additional checks
+ if not _handle_invalid_features(kb, kb_info):
+ ok = False
+
rules_mk_assignment_errors = _rules_mk_assignment_only(kb)
if rules_mk_assignment_errors:
ok = False
diff --git a/lib/python/qmk/cli/migrate.py b/lib/python/qmk/cli/migrate.py
index c1b1ad1ea9..0bab5c1949 100644
--- a/lib/python/qmk/cli/migrate.py
+++ b/lib/python/qmk/cli/migrate.py
@@ -47,9 +47,12 @@ def migrate(cli):
files = _candidate_files(cli.args.keyboard)
# Filter down keys if requested
- keys = info_map.keys()
+ keys = list(filter(lambda key: info_map[key].get("to_json", True), info_map.keys()))
if cli.args.filter:
keys = list(set(keys) & set(cli.args.filter))
+ rejected = set(cli.args.filter) - set(keys)
+ for key in rejected:
+ cli.log.info(f'{{fg_yellow}}Skipping {key} as migration not possible...')
cli.log.info(f'{{fg_green}}Migrating keyboard {{fg_cyan}}{cli.args.keyboard}{{fg_green}}.{{fg_reset}}')