summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli')
-rwxr-xr-xlib/python/qmk/cli/generate/api.py6
-rwxr-xr-xlib/python/qmk/cli/generate/keyboard_h.py44
-rw-r--r--lib/python/qmk/cli/generate/keycodes.py2
-rw-r--r--lib/python/qmk/cli/git/submodule.py21
-rwxr-xr-xlib/python/qmk/cli/info.py27
5 files changed, 90 insertions, 10 deletions
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py
index 580e080eeb..61a2f9f732 100755
--- a/lib/python/qmk/cli/generate/api.py
+++ b/lib/python/qmk/cli/generate/api.py
@@ -66,6 +66,12 @@ def _filtered_copy(src, dst):
dst.write_text(json.dumps(data, separators=(',', ':')), encoding='utf-8')
return dst
+ if dst.suffix == '.jsonschema':
+ data = json_load(src)
+
+ dst.write_text(json.dumps(data), encoding='utf-8')
+ return dst
+
return shutil.copy2(src, dst)
diff --git a/lib/python/qmk/cli/generate/keyboard_h.py b/lib/python/qmk/cli/generate/keyboard_h.py
index 152921bdce..fa4036e39a 100755
--- a/lib/python/qmk/cli/generate/keyboard_h.py
+++ b/lib/python/qmk/cli/generate/keyboard_h.py
@@ -11,12 +11,9 @@ from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.constants import COL_LETTERS, ROW_LETTERS, GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
-def _generate_layouts(keyboard):
- """Generates the layouts.h file.
+def _generate_layouts(keyboard, kb_info_json):
+ """Generates the layouts macros.
"""
- # Build the info.json file
- kb_info_json = info_json(keyboard)
-
if 'matrix_size' not in kb_info_json:
cli.log.error(f'{keyboard}: Invalid matrix config.')
return []
@@ -65,6 +62,32 @@ def _generate_layouts(keyboard):
return lines
+def _generate_keycodes(kb_info_json):
+ """Generates keyboard level keycodes.
+ """
+ if 'keycodes' not in kb_info_json:
+ return []
+
+ lines = []
+ lines.append('enum keyboard_keycodes {')
+
+ for index, item in enumerate(kb_info_json.get('keycodes')):
+ key = item["key"]
+ if index == 0:
+ lines.append(f' {key} = QK_KB_0,')
+ else:
+ lines.append(f' {key},')
+
+ lines.append('};')
+
+ for item in kb_info_json.get('keycodes', []):
+ key = item["key"]
+ for alias in item.get("aliases", []):
+ lines.append(f'#define {alias} {key}')
+
+ return lines
+
+
@cli.argument('-i', '--include', nargs='?', arg_only=True, help='Optional file to include')
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
@@ -73,8 +96,12 @@ def _generate_layouts(keyboard):
def generate_keyboard_h(cli):
"""Generates the keyboard.h file.
"""
+ # Build the info.json file
+ kb_info_json = info_json(cli.args.keyboard)
+
keyboard_h = cli.args.include
- dd_layouts = _generate_layouts(cli.args.keyboard)
+ dd_layouts = _generate_layouts(cli.args.keyboard, kb_info_json)
+ dd_keycodes = _generate_keycodes(kb_info_json)
valid_config = dd_layouts or keyboard_h
# Build the layouts.h file.
@@ -87,6 +114,11 @@ def generate_keyboard_h(cli):
if keyboard_h:
keyboard_h_lines.append(f'#include "{Path(keyboard_h).name}"')
+ keyboard_h_lines.append('')
+ keyboard_h_lines.append('// Keycode content')
+ if dd_keycodes:
+ keyboard_h_lines.extend(dd_keycodes)
+
# Protect against poorly configured keyboards
if not valid_config:
keyboard_h_lines.append('#error("<keyboard>.h is required unless your keyboard uses data-driven configuration. Please rename your keyboard\'s header file to <keyboard>.h")')
diff --git a/lib/python/qmk/cli/generate/keycodes.py b/lib/python/qmk/cli/generate/keycodes.py
index 17503bac63..3b69b17ed1 100644
--- a/lib/python/qmk/cli/generate/keycodes.py
+++ b/lib/python/qmk/cli/generate/keycodes.py
@@ -143,7 +143,7 @@ def generate_keycode_extras(cli):
"""
# Build the header file.
- keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "keymap.h"', '// clang-format off']
+ keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "keycodes.h"', '// clang-format off']
keycodes = load_spec(cli.args.version, cli.args.lang)
diff --git a/lib/python/qmk/cli/git/submodule.py b/lib/python/qmk/cli/git/submodule.py
index 9f354c021e..ef116ea124 100644
--- a/lib/python/qmk/cli/git/submodule.py
+++ b/lib/python/qmk/cli/git/submodule.py
@@ -7,14 +7,21 @@ from qmk import submodules
REMOVE_DIRS = [
'lib/ugfx',
- 'lib/pico-sdk',
'lib/chibios-contrib/ext/mcux-sdk',
- 'lib/lvgl',
+]
+
+IGNORE_DIRS = [
+ 'lib/arm_atsam',
+ 'lib/fnv',
+ 'lib/lib8tion',
+ 'lib/python',
+ 'lib/usbhost',
]
@cli.argument('--check', arg_only=True, action='store_true', help='Check if the submodules are dirty, and display a warning if they are.')
@cli.argument('--sync', arg_only=True, action='store_true', help='Shallow clone any missing submodules.')
+@cli.argument('-f', '--force', action='store_true', help='Flag to remove unexpected directories')
@cli.subcommand('Git Submodule actions.')
def git_submodule(cli):
"""Git Submodule actions
@@ -29,7 +36,15 @@ def git_submodule(cli):
cli.run(['git', 'submodule', 'update', '--depth=50', '--init', name], capture_output=False)
return True
- for folder in REMOVE_DIRS:
+ # can be the default behavior with: qmk config git_submodule.force=True
+ remove_dirs = REMOVE_DIRS
+ if cli.config.git_submodule.force:
+ # Also trash everything that isnt marked as "safe"
+ for path in normpath('lib').iterdir():
+ if not any(ignore in path.as_posix() for ignore in IGNORE_DIRS):
+ remove_dirs.append(path)
+
+ for folder in map(normpath, remove_dirs):
if normpath(folder).is_dir():
print(f"Removing '{folder}'")
shutil.rmtree(folder)
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py
index fa5729bcc9..839139346c 100755
--- a/lib/python/qmk/cli/info.py
+++ b/lib/python/qmk/cli/info.py
@@ -18,6 +18,29 @@ from qmk.path import is_keyboard
UNICODE_SUPPORT = sys.stdout.encoding.lower().startswith('utf')
+def _strip_api_content(info_json):
+ # Ideally this would only be added in the API pathway.
+ info_json.pop('platform', None)
+ info_json.pop('platform_key', None)
+ info_json.pop('processor_type', None)
+ info_json.pop('protocol', None)
+ info_json.pop('config_h_features', None)
+ info_json.pop('keymaps', None)
+ info_json.pop('keyboard_folder', None)
+ info_json.pop('parse_errors', None)
+ info_json.pop('parse_warnings', None)
+
+ for layout in info_json.get('layouts', {}).values():
+ layout.pop('filename', None)
+ layout.pop('c_macro', None)
+ layout.pop('json_layout', None)
+
+ if 'matrix_pins' in info_json:
+ info_json.pop('matrix_size', None)
+
+ return info_json
+
+
def show_keymap(kb_info_json, title_caps=True):
"""Render the keymap in ascii art.
"""
@@ -141,6 +164,7 @@ def print_parsed_rules_mk(keyboard_name):
@cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).')
@cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.')
@cli.argument('-r', '--rules-mk', action='store_true', help='Render the parsed values of the keyboard\'s rules.mk file.')
+@cli.argument('-a', '--api', action='store_true', help='Show fully processed info intended for API consumption.')
@cli.subcommand('Keyboard information.')
@automagic_keyboard
@automagic_keymap
@@ -171,6 +195,9 @@ def info(cli):
else:
kb_info_json = info_json(cli.config.info.keyboard)
+ if not cli.args.api:
+ kb_info_json = _strip_api_content(kb_info_json)
+
# Output in the requested format
if cli.args.format == 'json':
print(json.dumps(kb_info_json, cls=InfoJSONEncoder))