summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r--lib/python/qmk/cli/__init__.py9
-rwxr-xr-xlib/python/qmk/cli/cformat.py28
-rwxr-xr-xlib/python/qmk/cli/compile.py17
-rw-r--r--lib/python/qmk/cli/doctor/check.py75
-rw-r--r--lib/python/qmk/cli/doctor/linux.py11
-rwxr-xr-xlib/python/qmk/cli/doctor/main.py8
-rwxr-xr-xlib/python/qmk/cli/fileformat.py23
-rw-r--r--lib/python/qmk/cli/flash.py61
-rwxr-xr-xlib/python/qmk/cli/generate/api.py15
-rw-r--r--lib/python/qmk/cli/generate/keycodes.py55
-rw-r--r--lib/python/qmk/cli/generate/keycodes_tests.py39
-rw-r--r--lib/python/qmk/cli/git/__init__.py0
-rw-r--r--lib/python/qmk/cli/git/submodule.py38
-rw-r--r--lib/python/qmk/cli/list/keyboards.py3
-rwxr-xr-xlib/python/qmk/cli/mass_compile.py2
-rw-r--r--lib/python/qmk/cli/migrate.py81
-rwxr-xr-xlib/python/qmk/cli/multibuild.py106
-rw-r--r--lib/python/qmk/cli/new/keyboard.py10
-rwxr-xr-xlib/python/qmk/cli/new/keymap.py56
-rwxr-xr-xlib/python/qmk/cli/pyformat.py24
20 files changed, 388 insertions, 273 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index 1da4d25741..778eccada8 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -34,13 +34,11 @@ subcommands = [
'qmk.cli.bux',
'qmk.cli.c2json',
'qmk.cli.cd',
- 'qmk.cli.cformat',
'qmk.cli.chibios.confmigrate',
'qmk.cli.clean',
'qmk.cli.compile',
'qmk.cli.docs',
'qmk.cli.doctor',
- 'qmk.cli.fileformat',
'qmk.cli.flash',
'qmk.cli.format.c',
'qmk.cli.format.json',
@@ -57,9 +55,11 @@ subcommands = [
'qmk.cli.generate.keyboard_c',
'qmk.cli.generate.keyboard_h',
'qmk.cli.generate.keycodes',
+ 'qmk.cli.generate.keycodes_tests',
'qmk.cli.generate.rgb_breathe_table',
'qmk.cli.generate.rules_mk',
'qmk.cli.generate.version_h',
+ 'qmk.cli.git.submodule',
'qmk.cli.hello',
'qmk.cli.import.kbfirmware',
'qmk.cli.import.keyboard',
@@ -67,16 +67,15 @@ subcommands = [
'qmk.cli.info',
'qmk.cli.json2c',
'qmk.cli.lint',
+ 'qmk.cli.kle2json',
'qmk.cli.list.keyboards',
'qmk.cli.list.keymaps',
'qmk.cli.list.layouts',
- 'qmk.cli.kle2json',
'qmk.cli.mass_compile',
- 'qmk.cli.multibuild',
+ 'qmk.cli.migrate',
'qmk.cli.new.keyboard',
'qmk.cli.new.keymap',
'qmk.cli.painter',
- 'qmk.cli.pyformat',
'qmk.cli.pytest',
'qmk.cli.via2json',
]
diff --git a/lib/python/qmk/cli/cformat.py b/lib/python/qmk/cli/cformat.py
deleted file mode 100755
index 9d0ecaeba3..0000000000
--- a/lib/python/qmk/cli/cformat.py
+++ /dev/null
@@ -1,28 +0,0 @@
-"""Point people to the new command name.
-"""
-import sys
-from pathlib import Path
-
-from milc import cli
-
-
-@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Flag only, don't automatically format.")
-@cli.argument('-b', '--base-branch', default='origin/master', help='Branch to compare to diffs to.')
-@cli.argument('-a', '--all-files', arg_only=True, action='store_true', help='Format all core files.')
-@cli.argument('--core-only', arg_only=True, action='store_true', help='Format core files only.')
-@cli.argument('files', nargs='*', arg_only=True, help='Filename(s) to format.')
-@cli.subcommand('Pointer to the new command name: qmk format-c.', hidden=True)
-def cformat(cli):
- """Pointer to the new command name: qmk format-c.
- """
- cli.log.warning('"qmk cformat" has been renamed to "qmk format-c". Please use the new command in the future.')
- argv = [sys.executable, *sys.argv]
- argv[argv.index('cformat')] = 'format-c'
- script_path = Path(argv[1])
- script_path_exe = Path(f'{argv[1]}.exe')
-
- if not script_path.exists() and script_path_exe.exists():
- # For reasons I don't understand ".exe" is stripped from the script name on windows.
- argv[1] = str(script_path_exe)
-
- return cli.run(argv, capture_output=False).returncode
diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py
index 9e7629906f..f43e5f32de 100755
--- a/lib/python/qmk/cli/compile.py
+++ b/lib/python/qmk/cli/compile.py
@@ -10,7 +10,17 @@ import qmk.path
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json, build_environment
from qmk.keyboard import keyboard_completer, keyboard_folder
-from qmk.keymap import keymap_completer
+from qmk.keymap import keymap_completer, locate_keymap
+
+
+def _is_keymap_target(keyboard, keymap):
+ if keymap == 'all':
+ return True
+
+ if locate_keymap(keyboard, keymap):
+ return True
+
+ return False
@cli.argument('filename', nargs='?', arg_only=True, type=qmk.path.FileType('r'), completer=FilesCompleter('.json'), help='The configurator export to compile')
@@ -43,6 +53,11 @@ def compile(cli):
elif cli.config.compile.keyboard and cli.config.compile.keymap:
# Generate the make command for a specific keyboard/keymap.
+ if not _is_keymap_target(cli.config.compile.keyboard, cli.config.compile.keymap):
+ cli.log.error('Invalid keymap argument.')
+ cli.print_help()
+ return False
+
if cli.args.clean:
commands.append(create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, 'clean', **envs))
commands.append(create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, parallel=cli.config.compile.parallel, **envs))
diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py
index 8a0422ba72..426876e98a 100644
--- a/lib/python/qmk/cli/doctor/check.py
+++ b/lib/python/qmk/cli/doctor/check.py
@@ -3,7 +3,7 @@
from enum import Enum
import re
import shutil
-from subprocess import DEVNULL
+from subprocess import DEVNULL, TimeoutExpired
from milc import cli
from qmk import submodules
@@ -41,9 +41,8 @@ def _parse_gcc_version(version):
def _check_arm_gcc_version():
"""Returns True if the arm-none-eabi-gcc version is not known to cause problems.
"""
- if 'output' in ESSENTIAL_BINARIES['arm-none-eabi-gcc']:
- version_number = ESSENTIAL_BINARIES['arm-none-eabi-gcc']['output'].strip()
- cli.log.info('Found arm-none-eabi-gcc version %s', version_number)
+ version_number = ESSENTIAL_BINARIES['arm-none-eabi-gcc']['output'].strip()
+ cli.log.info('Found arm-none-eabi-gcc version %s', version_number)
return CheckStatus.OK # Right now all known arm versions are ok
@@ -51,44 +50,37 @@ def _check_arm_gcc_version():
def _check_avr_gcc_version():
"""Returns True if the avr-gcc version is not known to cause problems.
"""
- rc = CheckStatus.ERROR
- if 'output' in ESSENTIAL_BINARIES['avr-gcc']:
- version_number = ESSENTIAL_BINARIES['avr-gcc']['output'].strip()
+ version_number = ESSENTIAL_BINARIES['avr-gcc']['output'].strip()
+ cli.log.info('Found avr-gcc version %s', version_number)
- cli.log.info('Found avr-gcc version %s', version_number)
- rc = CheckStatus.OK
+ parsed_version = _parse_gcc_version(version_number)
+ if parsed_version['major'] > 8:
+ cli.log.warning('{fg_yellow}We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
+ return CheckStatus.WARNING
- parsed_version = _parse_gcc_version(version_number)
- if parsed_version['major'] > 8:
- cli.log.warning('{fg_yellow}We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
- rc = CheckStatus.WARNING
-
- return rc
+ return CheckStatus.OK
def _check_avrdude_version():
- if 'output' in ESSENTIAL_BINARIES['avrdude']:
- last_line = ESSENTIAL_BINARIES['avrdude']['output'].split('\n')[-2]
- version_number = last_line.split()[2][:-1]
- cli.log.info('Found avrdude version %s', version_number)
+ last_line = ESSENTIAL_BINARIES['avrdude']['output'].split('\n')[-2]
+ version_number = last_line.split()[2][:-1]
+ cli.log.info('Found avrdude version %s', version_number)
return CheckStatus.OK
def _check_dfu_util_version():
- if 'output' in ESSENTIAL_BINARIES['dfu-util']:
- first_line = ESSENTIAL_BINARIES['dfu-util']['output'].split('\n')[0]
- version_number = first_line.split()[1]
- cli.log.info('Found dfu-util version %s', version_number)
+ first_line = ESSENTIAL_BINARIES['dfu-util']['output'].split('\n')[0]
+ version_number = first_line.split()[1]
+ cli.log.info('Found dfu-util version %s', version_number)
return CheckStatus.OK
def _check_dfu_programmer_version():
- if 'output' in ESSENTIAL_BINARIES['dfu-programmer']:
- first_line = ESSENTIAL_BINARIES['dfu-programmer']['output'].split('\n')[0]
- version_number = first_line.split()[1]
- cli.log.info('Found dfu-programmer version %s', version_number)
+ first_line = ESSENTIAL_BINARIES['dfu-programmer']['output'].split('\n')[0]
+ version_number = first_line.split()[1]
+ cli.log.info('Found dfu-programmer version %s', version_number)
return CheckStatus.OK
@@ -96,11 +88,16 @@ def _check_dfu_programmer_version():
def check_binaries():
"""Iterates through ESSENTIAL_BINARIES and tests them.
"""
- ok = True
+ ok = CheckStatus.OK
for binary in sorted(ESSENTIAL_BINARIES):
- if not is_executable(binary):
- ok = False
+ try:
+ if not is_executable(binary):
+ ok = CheckStatus.ERROR
+ except TimeoutExpired:
+ cli.log.debug('Timeout checking %s', binary)
+ if ok != CheckStatus.ERROR:
+ ok = CheckStatus.WARNING
return ok
@@ -108,8 +105,22 @@ def check_binaries():
def check_binary_versions():
"""Check the versions of ESSENTIAL_BINARIES
"""
+ checks = {
+ 'arm-none-eabi-gcc': _check_arm_gcc_version,
+ 'avr-gcc': _check_avr_gcc_version,
+ 'avrdude': _check_avrdude_version,
+ 'dfu-util': _check_dfu_util_version,
+ 'dfu-programmer': _check_dfu_programmer_version,
+ }
+
versions = []
- for check in (_check_arm_gcc_version, _check_avr_gcc_version, _check_avrdude_version, _check_dfu_util_version, _check_dfu_programmer_version):
+ for binary in sorted(ESSENTIAL_BINARIES):
+ if 'output' not in ESSENTIAL_BINARIES[binary]:
+ cli.log.warning('Unknown version for %s', binary)
+ versions.append(CheckStatus.WARNING)
+ continue
+
+ check = checks[binary]
versions.append(check())
return versions
@@ -119,10 +130,8 @@ def check_submodules():
"""
for submodule in submodules.status().values():
if submodule['status'] is None:
- cli.log.error('Submodule %s has not yet been cloned!', submodule['name'])
return CheckStatus.ERROR
elif not submodule['status']:
- cli.log.warning('Submodule %s is not up to date!', submodule['name'])
return CheckStatus.WARNING
return CheckStatus.OK
diff --git a/lib/python/qmk/cli/doctor/linux.py b/lib/python/qmk/cli/doctor/linux.py
index a803305c0d..95bafe8c64 100644
--- a/lib/python/qmk/cli/doctor/linux.py
+++ b/lib/python/qmk/cli/doctor/linux.py
@@ -78,10 +78,13 @@ def check_udev_rules():
# Collect all rules from the config files
for rule_file in udev_rules:
- for line in rule_file.read_text(encoding='utf-8').split('\n'):
- line = line.strip()
- if not line.startswith("#") and len(line):
- current_rules.add(line)
+ try:
+ for line in rule_file.read_text(encoding='utf-8').split('\n'):
+ line = line.strip()
+ if not line.startswith("#") and len(line):
+ current_rules.add(line)
+ except PermissionError:
+ cli.log.debug("Failed to read: %s", rule_file)
# Check if the desired rules are among the currently present rules
for bootloader, rules in desired_rules.items():
diff --git a/lib/python/qmk/cli/doctor/main.py b/lib/python/qmk/cli/doctor/main.py
index 1600ab8dd4..6a6feb87d1 100755
--- a/lib/python/qmk/cli/doctor/main.py
+++ b/lib/python/qmk/cli/doctor/main.py
@@ -119,13 +119,15 @@ def doctor(cli):
# Make sure the basic CLI tools we need are available and can be executed.
bin_ok = check_binaries()
- if not bin_ok:
+ if bin_ok == CheckStatus.ERROR:
if yesno('Would you like to install dependencies?', default=True):
cli.run(['util/qmk_install.sh', '-y'], stdin=DEVNULL, capture_output=False)
bin_ok = check_binaries()
- if bin_ok:
+ if bin_ok == CheckStatus.OK:
cli.log.info('All dependencies are installed.')
+ elif bin_ok == CheckStatus.WARNING:
+ cli.log.warning('Issues encountered while checking dependencies.')
else:
status = CheckStatus.ERROR
@@ -142,7 +144,7 @@ def doctor(cli):
if sub_ok == CheckStatus.OK:
cli.log.info('Submodules are up to date.')
else:
- if yesno('Would you like to clone the submodules?', default=True):
+ if git_check_repo() and yesno('Would you like to clone the submodules?', default=True):
submodules.update()
sub_ok = check_submodules()
diff --git a/lib/python/qmk/cli/fileformat.py b/lib/python/qmk/cli/fileformat.py
deleted file mode 100755
index cee4ba1acd..0000000000
--- a/lib/python/qmk/cli/fileformat.py
+++ /dev/null
@@ -1,23 +0,0 @@
-"""Point people to the new command name.
-"""
-import sys
-from pathlib import Path
-
-from milc import cli
-
-
-@cli.subcommand('Pointer to the new command name: qmk format-text.', hidden=True)
-def fileformat(cli):
- """Pointer to the new command name: qmk format-text.
- """
- cli.log.warning('"qmk fileformat" has been renamed to "qmk format-text". Please use the new command in the future.')
- argv = [sys.executable, *sys.argv]
- argv[argv.index('fileformat')] = 'format-text'
- script_path = Path(argv[1])
- script_path_exe = Path(f'{argv[1]}.exe')
-
- if not script_path.exists() and script_path_exe.exists():
- # For reasons I don't understand ".exe" is stripped from the script name on windows.
- argv[1] = str(script_path_exe)
-
- return cli.run(argv, capture_output=False).returncode
diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py
index 40bfbdab56..8724f26889 100644
--- a/lib/python/qmk/cli/flash.py
+++ b/lib/python/qmk/cli/flash.py
@@ -11,12 +11,24 @@ import qmk.path
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json, build_environment
from qmk.keyboard import keyboard_completer, keyboard_folder
+from qmk.keymap import keymap_completer, locate_keymap
from qmk.flashers import flasher
-def print_bootloader_help():
+def _is_keymap_target(keyboard, keymap):
+ if keymap == 'all':
+ return True
+
+ if locate_keymap(keyboard, keymap):
+ return True
+
+ return False
+
+
+def _list_bootloaders():
"""Prints the available bootloaders listed in docs.qmk.fm.
"""
+ cli.print_help()
cli.log.info('Here are the available bootloaders:')
cli.echo('\tavrdude')
cli.echo('\tbootloadhid')
@@ -36,14 +48,29 @@ def print_bootloader_help():
cli.echo('\tuf2-split-left')
cli.echo('\tuf2-split-right')
cli.echo('For more info, visit https://docs.qmk.fm/#/flashing')
+ return False
+
+
+def _flash_binary(filename, mcu):
+ """Try to flash binary firmware
+ """
+ cli.echo('Flashing binary firmware...\nPlease reset your keyboard into bootloader mode now!\nPress Ctrl-C to exit.\n')
+ try:
+ err, msg = flasher(mcu, filename)
+ if err:
+ cli.log.error(msg)
+ return False
+ except KeyboardInterrupt:
+ cli.log.info('Ctrl-C was pressed, exiting...')
+ return True
@cli.argument('filename', nargs='?', arg_only=True, type=qmk.path.FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON to be compiled and flashed or a pre-compiled binary firmware file (bin/hex) to be flashed.')
@cli.argument('-b', '--bootloaders', action='store_true', help='List the available bootloaders.')
@cli.argument('-bl', '--bootloader', default='flash', help='The flash command, corresponding to qmk\'s make options of bootloaders.')
@cli.argument('-m', '--mcu', help='The MCU name. Required for HalfKay, HID, USBAspLoader and ISP flashing.')
-@cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.')
-@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.')
+@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.')
+@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.")
@cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.")
@cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.")
@@ -56,30 +83,17 @@ def flash(cli):
If a binary firmware is supplied, try to flash that.
- If a Configurator JSON export is supplied this command will create a new keymap. Keymap and Keyboard arguments
- will be ignored.
+ If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.
- If no file is supplied, keymap and keyboard are expected.
+ If a keyboard and keymap are provided this command will build a firmware based on that.
If bootloader is omitted the make system will use the configured bootloader for that keyboard.
"""
- if cli.args.filename and cli.args.filename.suffix in ['.bin', '.hex']:
- # Try to flash binary firmware
- cli.echo('Flashing binary firmware...\nPlease reset your keyboard into bootloader mode now!\nPress Ctrl-C to exit.\n')
- try:
- err, msg = flasher(cli.args.mcu, cli.args.filename)
- if err:
- cli.log.error(msg)
- return False
- except KeyboardInterrupt:
- cli.log.info('Ctrl-C was pressed, exiting...')
- return True
+ if cli.args.filename and cli.args.filename.suffix in ['.bin', '.hex', '.uf2']:
+ return _flash_binary(cli.args.filename, cli.args.mcu)
if cli.args.bootloaders:
- # Provide usage and list bootloaders
- cli.print_help()
- print_bootloader_help()
- return False
+ return _list_bootloaders()
# Build the environment vars
envs = build_environment(cli.args.env)
@@ -94,6 +108,11 @@ def flash(cli):
elif cli.config.flash.keyboard and cli.config.flash.keymap:
# Generate the make command for a specific keyboard/keymap.
+ if not _is_keymap_target(cli.config.flash.keyboard, cli.config.flash.keymap):
+ cli.log.error('Invalid keymap argument.')
+ cli.print_help()
+ return False
+
if cli.args.clean:
commands.append(create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, 'clean', **envs))
commands.append(create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader, parallel=cli.config.flash.parallel, **envs))
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py
index 8650a36b84..d662e14e00 100755
--- a/lib/python/qmk/cli/generate/api.py
+++ b/lib/python/qmk/cli/generate/api.py
@@ -10,8 +10,9 @@ from qmk.datetime import current_datetime
from qmk.info import info_json
from qmk.json_encoders import InfoJSONEncoder
from qmk.json_schema import json_load
+from qmk.keymap import list_keymaps
from qmk.keyboard import find_readme, list_keyboards
-from qmk.keycodes import load_spec, list_versions
+from qmk.keycodes import load_spec, list_versions, list_languages
DATA_PATH = Path('data')
TEMPLATE_PATH = DATA_PATH / 'templates/api/'
@@ -44,6 +45,13 @@ def _resolve_keycode_specs(output_folder):
output_file = output_folder / f'constants/keycodes_{version}.json'
output_file.write_text(json.dumps(overall, indent=4), encoding='utf-8')
+ for lang in list_languages():
+ for version in list_versions(lang):
+ overall = load_spec(version, lang)
+
+ output_file = output_folder / f'constants/keycodes_{lang}_{version}.json'
+ output_file.write_text(json.dumps(overall, indent=4), encoding='utf-8')
+
# Purge files consumed by 'load_spec'
shutil.rmtree(output_folder / 'constants/keycodes/')
@@ -104,6 +112,11 @@ def generate_api(cli):
# Generate and write keyboard specific JSON files
for keyboard_name in keyboard_list:
kb_all[keyboard_name] = info_json(keyboard_name)
+
+ # Populate the list of JSON keymaps
+ for keymap in list_keymaps(keyboard_name, c=False, fullpath=True):
+ kb_all[keyboard_name]['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'}
+
keyboard_dir = v1_dir / 'keyboards' / keyboard_name
keyboard_info = keyboard_dir / 'info.json'
keyboard_readme = keyboard_dir / 'readme.md'
diff --git a/lib/python/qmk/cli/generate/keycodes.py b/lib/python/qmk/cli/generate/keycodes.py
index 29b7db3c80..2ed84cd589 100644
--- a/lib/python/qmk/cli/generate/keycodes.py
+++ b/lib/python/qmk/cli/generate/keycodes.py
@@ -8,6 +8,24 @@ from qmk.path import normpath
from qmk.keycodes import load_spec
+def _render_key(key):
+ width = 7
+ if 'S(' in key:
+ width += len('S()')
+ if 'A(' in key:
+ width += len('A()')
+ if 'RCTL(' in key:
+ width += len('RCTL()')
+ if 'ALGR(' in key:
+ width += len('ALGR()')
+ return key.ljust(width)
+
+
+def _render_label(label):
+ label = label.replace("\\", "(backslash)")
+ return label
+
+
def _generate_ranges(lines, keycodes):
lines.append('')
lines.append('enum qk_keycode_ranges {')
@@ -67,6 +85,23 @@ def _generate_helpers(lines, keycodes):
lines.append(f'#define IS_{ group.upper() }_KEYCODE(code) ((code) >= {lo} && (code) <= {hi})')
+def _generate_aliases(lines, keycodes):
+ lines.append('')
+ lines.append('// Aliases')
+ for key, value in keycodes["aliases"].items():
+ define = _render_key(value.get("key"))
+ val = _render_key(key)
+ if 'label' in value:
+ lines.append(f'#define {define} {val} // {_render_label(value.get("label"))}')
+ else:
+ lines.append(f'#define {define} {val}')
+
+ lines.append('')
+ for key, value in keycodes["aliases"].items():
+ for alias in value.get("aliases", []):
+ lines.append(f'#define {alias} {value.get("key")}')
+
+
@cli.argument('-v', '--version', arg_only=True, required=True, help='Version of keycodes to generate.')
@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")
@@ -86,3 +121,23 @@ def generate_keycodes(cli):
# Show the results
dump_lines(cli.args.output, keycodes_h_lines, cli.args.quiet)
+
+
+@cli.argument('-v', '--version', arg_only=True, required=True, help='Version of keycodes to generate.')
+@cli.argument('-l', '--lang', arg_only=True, required=True, help='Language of keycodes to generate.')
+@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")
+@cli.subcommand('Used by the make system to generate keymap_{lang}.h from keycodes_{lang}_{version}.json', hidden=True)
+def generate_keycode_extras(cli):
+ """Generates the header file.
+ """
+
+ # Build the header file.
+ keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "keymap.h"', '// clang-format off']
+
+ keycodes = load_spec(cli.args.version, cli.args.lang)
+
+ _generate_aliases(keycodes_h_lines, keycodes)
+
+ # Show the results
+ dump_lines(cli.args.output, keycodes_h_lines, cli.args.quiet)
diff --git a/lib/python/qmk/cli/generate/keycodes_tests.py b/lib/python/qmk/cli/generate/keycodes_tests.py
new file mode 100644
index 0000000000..453b4693a7
--- /dev/null
+++ b/lib/python/qmk/cli/generate/keycodes_tests.py
@@ -0,0 +1,39 @@
+"""Used by the make system to generate a keycode lookup table from keycodes_{version}.json
+"""
+from milc import cli
+
+from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
+from qmk.commands import dump_lines
+from qmk.path import normpath
+from qmk.keycodes import load_spec
+
+
+def _generate_defines(lines, keycodes):
+ lines.append('')
+ lines.append('std::map<uint16_t, std::string> KEYCODE_ID_TABLE = {')
+ for key, value in keycodes["keycodes"].items():
+ lines.append(f' {{{value.get("key")}, "{value.get("key")}"}},')
+ lines.append('};')
+
+
+@cli.argument('-v', '--version', arg_only=True, required=True, help='Version of keycodes to generate.')
+@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")
+@cli.subcommand('Used by the make system to generate a keycode lookup table from keycodes_{version}.json', hidden=True)
+def generate_keycodes_tests(cli):
+ """Generates a keycode to identifier lookup table for unit test output.
+ """
+
+ # Build the keycodes.h file.
+ keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '// clang-format off']
+ keycodes_h_lines.append('extern "C" {\n#include <keycode.h>\n}')
+ keycodes_h_lines.append('#include <map>')
+ keycodes_h_lines.append('#include <string>')
+ keycodes_h_lines.append('#include <cstdint>')
+
+ keycodes = load_spec(cli.args.version)
+
+ _generate_defines(keycodes_h_lines, keycodes)
+
+ # Show the results
+ dump_lines(cli.args.output, keycodes_h_lines, cli.args.quiet)
diff --git a/lib/python/qmk/cli/git/__init__.py b/lib/python/qmk/cli/git/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/lib/python/qmk/cli/git/__init__.py
diff --git a/lib/python/qmk/cli/git/submodule.py b/lib/python/qmk/cli/git/submodule.py
new file mode 100644
index 0000000000..9f354c021e
--- /dev/null
+++ b/lib/python/qmk/cli/git/submodule.py
@@ -0,0 +1,38 @@
+import shutil
+
+from milc import cli
+
+from qmk.path import normpath
+from qmk import submodules
+
+REMOVE_DIRS = [
+ 'lib/ugfx',
+ 'lib/pico-sdk',
+ 'lib/chibios-contrib/ext/mcux-sdk',
+ 'lib/lvgl',
+]
+
+
+@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.subcommand('Git Submodule actions.')
+def git_submodule(cli):
+ """Git Submodule actions
+ """
+ if cli.args.check:
+ return all(item['status'] for item in submodules.status().values())
+
+ if cli.args.sync:
+ cli.run(['git', 'submodule', 'sync', '--recursive'])
+ for name, item in submodules.status().items():
+ if item['status'] is None:
+ cli.run(['git', 'submodule', 'update', '--depth=50', '--init', name], capture_output=False)
+ return True
+
+ for folder in REMOVE_DIRS:
+ if normpath(folder).is_dir():
+ print(f"Removing '{folder}'")
+ shutil.rmtree(folder)
+
+ cli.run(['git', 'submodule', 'sync', '--recursive'], capture_output=False)
+ cli.run(['git', 'submodule', 'update', '--init', '--recursive', '--progress'], capture_output=False)
diff --git a/lib/python/qmk/cli/list/keyboards.py b/lib/python/qmk/cli/list/keyboards.py
index 8b6c451673..405b9210e4 100644
--- a/lib/python/qmk/cli/list/keyboards.py
+++ b/lib/python/qmk/cli/list/keyboards.py
@@ -5,9 +5,10 @@ from milc import cli
import qmk.keyboard
+@cli.argument('--no-resolve-defaults', arg_only=True, action='store_false', help='Ignore any "DEFAULT_FOLDER" within keyboards rules.mk')
@cli.subcommand("List the keyboards currently defined within QMK")
def list_keyboards(cli):
"""List the keyboards currently defined within QMK
"""
- for keyboard_name in qmk.keyboard.list_keyboards():
+ for keyboard_name in qmk.keyboard.list_keyboards(cli.args.no_resolve_defaults):
print(keyboard_name)
diff --git a/lib/python/qmk/cli/mass_compile.py b/lib/python/qmk/cli/mass_compile.py
index a98f7ad482..d8dda0cac3 100755
--- a/lib/python/qmk/cli/mass_compile.py
+++ b/lib/python/qmk/cli/mass_compile.py
@@ -134,7 +134,7 @@ all: {keyboard_safe}_{keymap_name}_binary
{keyboard_safe}_{keymap_name}_binary:
@rm -f "{QMK_FIRMWARE}/.build/failed.log.{keyboard_safe}.{keymap_name}" || true
@echo "Compiling QMK Firmware for target: '{keyboard_name}:{keymap_name}'..." >>"{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}"
- +@$(MAKE) -C "{QMK_FIRMWARE}" -f "{QMK_FIRMWARE}/builddefs/build_keyboard.mk" KEYBOARD="{keyboard_name}" KEYMAP="{keymap_name}" REQUIRE_PLATFORM_KEY= COLOR=true SILENT=false {' '.join(cli.args.env)} \\
+ +@$(MAKE) -C "{QMK_FIRMWARE}" -f "{QMK_FIRMWARE}/builddefs/build_keyboard.mk" KEYBOARD="{keyboard_name}" KEYMAP="{keymap_name}" COLOR=true SILENT=false {' '.join(cli.args.env)} \\
>>"{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" 2>&1 \\
|| cp "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" "{QMK_FIRMWARE}/.build/failed.log.{os.getpid()}.{keyboard_safe}.{keymap_name}"
@{{ grep '\[ERRORS\]' "{QMK_FIRMWARE}/.build/build.log.{os.getpid()}.{keyboard_safe}.{keymap_name}" >/dev/null 2>&1 && printf "Build %-64s \e[1;31m[ERRORS]\e[0m\\n" "{keyboard_name}:{keymap_name}" ; }} \\
diff --git a/lib/python/qmk/cli/migrate.py b/lib/python/qmk/cli/migrate.py
new file mode 100644
index 0000000000..4164f9c8ad
--- /dev/null
+++ b/lib/python/qmk/cli/migrate.py
@@ -0,0 +1,81 @@
+"""Migrate keyboard configuration to "Data Driven"
+"""
+import json
+from pathlib import Path
+from dotty_dict import dotty
+
+from milc import cli
+
+from qmk.keyboard import keyboard_completer, keyboard_folder, resolve_keyboard
+from qmk.info import info_json, find_info_json
+from qmk.json_encoders import InfoJSONEncoder
+from qmk.json_schema import json_load
+
+
+def _candidate_files(keyboard):
+ kb_dir = Path(resolve_keyboard(keyboard))
+
+ cur_dir = Path('keyboards')
+ files = []
+ for dir in kb_dir.parts:
+ cur_dir = cur_dir / dir
+ files.append(cur_dir / 'config.h')
+ files.append(cur_dir / 'rules.mk')
+
+ return [file for file in files if file.exists()]
+
+
+@cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the performed migrations based on the supplied value. Supported format is 'KEY' located from 'data/mappings'. May be passed multiple times.")
+@cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='The keyboard\'s name')
+@cli.subcommand('Migrate keyboard config to "Data Driven".', hidden=True)
+def migrate(cli):
+ """Migrate keyboard configuration to "Data Driven"
+ """
+ # Merge mappings as we do not care to where "KEY" is found just that its removed
+ info_config_map = json_load(Path('data/mappings/info_config.hjson'))
+ info_rules_map = json_load(Path('data/mappings/info_rules.hjson'))
+ info_map = {**info_config_map, **info_rules_map}
+
+ # Parse target info.json which will receive updates
+ target_info = Path(find_info_json(cli.args.keyboard)[0])
+ info_data = dotty(json_load(target_info))
+
+ # Already parsed used for updates
+ kb_info_json = dotty(info_json(cli.args.keyboard))
+
+ # List of candidate files
+ files = _candidate_files(cli.args.keyboard)
+
+ # Filter down keys if requested
+ keys = info_map.keys()
+ if cli.args.filter:
+ keys = list(set(keys) & set(cli.args.filter))
+
+ cli.log.info(f'{{fg_green}}Migrating keyboard {{fg_c