From 4f8cc32cf50fb2b6eb3764a7d971c41121c9bc89 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Mon, 21 Mar 2022 10:57:41 +0000 Subject: Extend 'qmk info' to handle keymap level overrides (#16702) --- lib/python/qmk/cli/generate/config_h.py | 10 +++------- lib/python/qmk/cli/generate/rules_mk.py | 10 +++------- lib/python/qmk/cli/info.py | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'lib/python/qmk/cli') diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index adefdb5732..20c9595ed7 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -5,10 +5,9 @@ from pathlib import Path from dotty_dict import dotty from milc import cli -from qmk.info import info_json -from qmk.json_schema import json_load, validate +from qmk.info import info_json, keymap_json_config +from qmk.json_schema import json_load from qmk.keyboard import keyboard_completer, keyboard_folder -from qmk.keymap import locate_keymap from qmk.commands import dump_lines from qmk.path import normpath from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE @@ -180,10 +179,7 @@ def generate_config_h(cli): """ # Determine our keyboard/keymap if cli.args.keymap: - km = locate_keymap(cli.args.keyboard, cli.args.keymap) - km_json = json_load(km) - validate(km_json, 'qmk.keymap.v1') - kb_info_json = dotty(km_json.get('config', {})) + kb_info_json = dotty(keymap_json_config(cli.args.keyboard, cli.args.keymap)) else: kb_info_json = dotty(info_json(cli.args.keyboard)) diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 6f342c6567..9623d00fb5 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -5,10 +5,9 @@ from pathlib import Path from dotty_dict import dotty from milc import cli -from qmk.info import info_json -from qmk.json_schema import json_load, validate +from qmk.info import info_json, keymap_json_config +from qmk.json_schema import json_load from qmk.keyboard import keyboard_completer, keyboard_folder -from qmk.keymap import locate_keymap from qmk.commands import dump_lines from qmk.path import normpath from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE @@ -51,10 +50,7 @@ def generate_rules_mk(cli): """ # Determine our keyboard/keymap if cli.args.keymap: - km = locate_keymap(cli.args.keyboard, cli.args.keymap) - km_json = json_load(km) - validate(km_json, 'qmk.keymap.v1') - kb_info_json = dotty(km_json.get('config', {})) + kb_info_json = dotty(keymap_json_config(cli.args.keyboard, cli.args.keymap)) else: kb_info_json = dotty(info_json(cli.args.keyboard)) diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index 3131d4b53f..fa5729bcc9 100755 --- a/lib/python/qmk/cli/info.py +++ b/lib/python/qmk/cli/info.py @@ -11,8 +11,8 @@ from qmk.json_encoders import InfoJSONEncoder from qmk.constants import COL_LETTERS, ROW_LETTERS from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.keyboard import keyboard_completer, keyboard_folder, render_layouts, render_layout, rules_mk +from qmk.info import info_json, keymap_json from qmk.keymap import locate_keymap -from qmk.info import info_json from qmk.path import is_keyboard UNICODE_SUPPORT = sys.stdout.encoding.lower().startswith('utf') @@ -135,7 +135,7 @@ def print_parsed_rules_mk(keyboard_name): @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to show info for.') -@cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.') +@cli.argument('-km', '--keymap', help='Keymap to show info for (Optional).') @cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') @cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.') @cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).') @@ -161,8 +161,15 @@ def info(cli): print_parsed_rules_mk(cli.config.info.keyboard) return False + # default keymap stored in config file should be ignored + if cli.config_source.info.keymap == 'config_file': + cli.config_source.info.keymap = None + # Build the info.json file - kb_info_json = info_json(cli.config.info.keyboard) + if cli.config.info.keymap: + kb_info_json = keymap_json(cli.config.info.keyboard, cli.config.info.keymap) + else: + kb_info_json = info_json(cli.config.info.keyboard) # Output in the requested format if cli.args.format == 'json': @@ -178,11 +185,12 @@ def info(cli): cli.log.error('Unknown format: %s', cli.args.format) return False + # Output requested extras if cli.config.info.layouts: show_layouts(kb_info_json, title_caps) if cli.config.info.matrix: show_matrix(kb_info_json, title_caps) - if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file': + if cli.config.info.keymap: show_keymap(kb_info_json, title_caps) -- cgit v1.2.3