summaryrefslogtreecommitdiffstats
path: root/lib/python
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2022-10-19 17:43:25 +0100
committerGitHub <noreply@github.com>2022-10-19 17:43:25 +0100
commitaa8e0a3e7aa9268136fea31d5fd5832e91c0ccc4 (patch)
tree43849250d4e1893f94a8062f9868e2bea5b0804f /lib/python
parent18dc851e37a203b32db0261c365dd300488e1c71 (diff)
Build correctly when out of tree (#18775)
Diffstat (limited to 'lib/python')
-rwxr-xr-xlib/python/qmk/cli/generate/config_h.py24
-rwxr-xr-xlib/python/qmk/cli/generate/rules_mk.py24
2 files changed, 30 insertions, 18 deletions
diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py
index 3752174841..fa7c43788d 100755
--- a/lib/python/qmk/cli/generate/config_h.py
+++ b/lib/python/qmk/cli/generate/config_h.py
@@ -1,15 +1,16 @@
"""Used by the make system to generate info_config.h from info.json.
"""
from pathlib import Path
-
from dotty_dict import dotty
+
+from argcomplete.completers import FilesCompleter
from milc import cli
-from qmk.info import info_json, keymap_json_config
+from qmk.info import info_json
from qmk.json_schema import json_load
from qmk.keyboard import keyboard_completer, keyboard_folder
-from qmk.commands import dump_lines
-from qmk.path import normpath
+from qmk.commands import dump_lines, parse_configurator_json
+from qmk.path import normpath, FileType
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
@@ -162,19 +163,24 @@ def generate_led_animations_config(led_feature_json, config_h_lines, prefix):
config_h_lines.append(generate_define(f'{prefix}{animation.upper()}'))
+@cli.argument('filename', nargs='?', arg_only=True, type=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('-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.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate config.h for.')
-@cli.argument('-km', '--keymap', arg_only=True, help='Keymap to generate config.h for.')
+@cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate config.h for.')
@cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True)
def generate_config_h(cli):
"""Generates the info_config.h file.
"""
# Determine our keyboard/keymap
- if cli.args.keymap:
- kb_info_json = dotty(keymap_json_config(cli.args.keyboard, cli.args.keymap))
- else:
+ if cli.args.filename:
+ user_keymap = parse_configurator_json(cli.args.filename)
+ kb_info_json = user_keymap.get('config', {})
+ elif cli.args.keyboard:
kb_info_json = dotty(info_json(cli.args.keyboard))
+ else:
+ cli.log.error('You must supply a configurator export or `--keyboard`.')
+ cli.subcommands['generate-config-h'].print_help()
+ return False
# Build the info_config.h file.
config_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once']
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py
index 9623d00fb5..361d3c758a 100755
--- a/lib/python/qmk/cli/generate/rules_mk.py
+++ b/lib/python/qmk/cli/generate/rules_mk.py
@@ -1,15 +1,16 @@
"""Used by the make system to generate a rules.mk
"""
from pathlib import Path
-
from dotty_dict import dotty
+
+from argcomplete.completers import FilesCompleter
from milc import cli
-from qmk.info import info_json, keymap_json_config
+from qmk.info import info_json
from qmk.json_schema import json_load
from qmk.keyboard import keyboard_completer, keyboard_folder
-from qmk.commands import dump_lines
-from qmk.path import normpath
+from qmk.commands import dump_lines, parse_configurator_json
+from qmk.path import normpath, FileType
from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE
@@ -39,20 +40,25 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
return f'{rules_key} ?= {rules_value}'
+@cli.argument('filename', nargs='?', arg_only=True, type=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('-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.argument('-e', '--escape', arg_only=True, action='store_true', help="Escape spaces in quiet mode")
-@cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate rules.mk for.')
-@cli.argument('-km', '--keymap', arg_only=True, help='Keymap to generate rules.mk for.')
+@cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate rules.mk for.')
@cli.subcommand('Used by the make system to generate rules.mk from info.json', hidden=True)
def generate_rules_mk(cli):
"""Generates a rules.mk file from info.json.
"""
# Determine our keyboard/keymap
- if cli.args.keymap:
- kb_info_json = dotty(keymap_json_config(cli.args.keyboard, cli.args.keymap))
- else:
+ if cli.args.filename:
+ user_keymap = parse_configurator_json(cli.args.filename)
+ kb_info_json = user_keymap.get('config', {})
+ elif cli.args.keyboard:
kb_info_json = dotty(info_json(cli.args.keyboard))
+ else:
+ cli.log.error('You must supply a configurator export or `--keyboard`.')
+ cli.subcommands['generate-rules-mk'].print_help()
+ return False
info_rules_map = json_load(Path('data/mappings/info_rules.json'))
rules_mk_lines = [GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE]