From fc0330a54a180c6e0d9de93277f23421ea143c03 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 19 Oct 2022 11:29:44 +0100 Subject: Correctly build keymap.json containing additional config (#18766) --- lib/python/qmk/commands.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/python/qmk/commands.py') diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 9c0a5dce56..2ab506c710 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -2,13 +2,13 @@ """ import os import sys +import json import shutil from pathlib import Path from milc import cli import jsonschema -import qmk.keymap from qmk.constants import KEYBOARD_OUTPUT_PREFIX from qmk.json_schema import json_load, validate @@ -134,12 +134,11 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va target = f'{keyboard_filesafe}_{user_keymap["keymap"]}' keyboard_output = Path(f'{KEYBOARD_OUTPUT_PREFIX}{keyboard_filesafe}') keymap_output = Path(f'{keyboard_output}_{user_keymap["keymap"]}') - c_text = qmk.keymap.generate_c(user_keymap) keymap_dir = keymap_output / 'src' - keymap_c = keymap_dir / 'keymap.c' + keymap_json = keymap_dir / 'keymap.json' keymap_dir.mkdir(exist_ok=True, parents=True) - keymap_c.write_text(c_text) + keymap_json.write_text(json.dumps(user_keymap), encoding='utf-8') # Return a command that can be run to make the keymap and flash if given verbose = 'true' if cli.config.general.verbose else 'false' @@ -175,7 +174,7 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va f'MAIN_KEYMAP_PATH_3={keymap_output}', f'MAIN_KEYMAP_PATH_4={keymap_output}', f'MAIN_KEYMAP_PATH_5={keymap_output}', - f'KEYMAP_C={keymap_c}', + f'KEYMAP_JSON={keymap_json}', f'KEYMAP_PATH={keymap_dir}', f'VERBOSE={verbose}', f'COLOR={color}', -- cgit v1.2.3 From 0b41c13509b5547028f141d869e10199566a1228 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Thu, 20 Oct 2022 14:35:27 +0100 Subject: [CLI] Ensure consistent clean behaviour (#18781) --- lib/python/qmk/commands.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'lib/python/qmk/commands.py') diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 2ab506c710..07826a4866 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -107,7 +107,7 @@ def get_make_parallel_args(parallel=1): return parallel_args -def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_vars): +def compile_configurator_json(user_keymap, bootloader=None, parallel=1, clean=False, **env_vars): """Convert a configurator export JSON file into a C file and then compile it. Args: @@ -129,7 +129,6 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va # e.g.: qmk compile - < keyboards/clueboard/california/keymaps/default/keymap.json user_keymap["keymap"] = user_keymap.get("keymap", "default_json") - # Write the keymap.c file keyboard_filesafe = user_keymap['keyboard'].replace('/', '_') target = f'{keyboard_filesafe}_{user_keymap["keymap"]}' keyboard_output = Path(f'{KEYBOARD_OUTPUT_PREFIX}{keyboard_filesafe}') @@ -137,8 +136,25 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va keymap_dir = keymap_output / 'src' keymap_json = keymap_dir / 'keymap.json' + if clean: + if keyboard_output.exists(): + shutil.rmtree(keyboard_output) + if keymap_output.exists(): + shutil.rmtree(keymap_output) + + # begin with making the deepest folder in the tree keymap_dir.mkdir(exist_ok=True, parents=True) - keymap_json.write_text(json.dumps(user_keymap), encoding='utf-8') + + # Compare minified to ensure consistent comparison + new_content = json.dumps(user_keymap, separators=(',', ':')) + if keymap_json.exists(): + old_content = json.dumps(json.loads(keymap_json.read_text(encoding='utf-8')), separators=(',', ':')) + if old_content == new_content: + new_content = None + + # Write the keymap.json file if different + if new_content: + keymap_json.write_text(new_content, encoding='utf-8') # Return a command that can be run to make the keymap and flash if given verbose = 'true' if cli.config.general.verbose else 'false' @@ -210,6 +226,19 @@ def parse_configurator_json(configurator_file): return user_keymap +def build_environment(args): + """Common processing for cli.args.env + """ + envs = {} + for env in args: + if '=' in env: + key, value = env.split('=', 1) + envs[key] = value + else: + cli.log.warning('Invalid environment variable: %s', env) + return envs + + def in_virtualenv(): """Check if running inside a virtualenv. Based on https://stackoverflow.com/a/1883251 -- cgit v1.2.3 From 479d8de622674b6667295bda344145a69aa042bd Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 8 Nov 2022 12:05:08 +1100 Subject: Format DD mappings and schemas (#18924) --- lib/python/qmk/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/python/qmk/commands.py') diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 07826a4866..5561a354c5 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -214,7 +214,7 @@ def parse_configurator_json(configurator_file): exit(1) orig_keyboard = user_keymap['keyboard'] - aliases = json_load(Path('data/mappings/keyboard_aliases.json')) + aliases = json_load(Path('data/mappings/keyboard_aliases.hjson')) if orig_keyboard in aliases: if 'target' in aliases[orig_keyboard]: -- cgit v1.2.3 [cgit] Unable to lock slot /tmp/cgit/33300000.lock: Permission denied (13)