From 9f387f525cb7f9099c4a90ad42d1195c1901c2a3 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 4 Aug 2024 01:55:02 +1000 Subject: Remove `handwired/pytest/has_template` (#24232) --- lib/python/qmk/tests/test_qmk_keymap.py | 45 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'lib/python/qmk/tests/test_qmk_keymap.py') diff --git a/lib/python/qmk/tests/test_qmk_keymap.py b/lib/python/qmk/tests/test_qmk_keymap.py index 5e2efc1232..b4b8f4bbe0 100644 --- a/lib/python/qmk/tests/test_qmk_keymap.py +++ b/lib/python/qmk/tests/test_qmk_keymap.py @@ -11,30 +11,43 @@ def test_template_json_pytest_basic(): assert templ == {'keyboard': 'handwired/pytest/basic'} -def test_template_c_pytest_has_template(): - templ = qmk.keymap.template_c('handwired/pytest/has_template') - assert templ == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {__KEYMAP_GOES_HERE__};\n' - - -def test_template_json_pytest_has_template(): - templ = qmk.keymap.template_json('handwired/pytest/has_template') - assert templ == {'keyboard': 'handwired/pytest/has_template', "documentation": "This file is a keymap.json file for handwired/pytest/has_template"} - - -def test_generate_c_pytest_has_template(): +def test_generate_c_pytest_basic(): keymap_json = { - 'keyboard': 'handwired/pytest/has_template', + 'keyboard': 'handwired/pytest/basic', 'layout': 'LAYOUT', 'layers': [['KC_A']], 'macros': None, } templ = qmk.keymap.generate_c(keymap_json) - assert templ == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT(KC_A)};\n' + assert templ == """#include QMK_KEYBOARD_H +#if __has_include("keymap.h") +# include "keymap.h" +#endif + + +/* THIS FILE WAS GENERATED! + * + * This file was generated by qmk json2c. You may or may not want to + * edit it directly. + */ +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { +\t[0] = LAYOUT(KC_A) +}; + +#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + +}; +#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) + + + +""" -def test_generate_json_pytest_has_template(): - templ = qmk.keymap.generate_json('default', 'handwired/pytest/has_template', 'LAYOUT', [['KC_A']]) - assert templ == {"keyboard": "handwired/pytest/has_template", "documentation": "This file is a keymap.json file for handwired/pytest/has_template", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_A"]]} +def test_generate_json_pytest_basic(): + templ = qmk.keymap.generate_json('default', 'handwired/pytest/basic', 'LAYOUT', [['KC_A']]) + assert templ == {"keyboard": "handwired/pytest/basic", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_A"]]} def test_parse_keymap_c(): -- cgit v1.2.3 From 1f942bb17e0f324f81788106a72c7573304d65ff Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 4 Aug 2024 21:28:40 +1000 Subject: Small tweaks to keymap generation (#24240) --- lib/python/qmk/keymap.py | 5 ++--- lib/python/qmk/tests/test_cli_commands.py | 6 ++---- lib/python/qmk/tests/test_qmk_keymap.py | 3 +-- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'lib/python/qmk/tests/test_qmk_keymap.py') diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index ca76f1b288..8c09cc51dc 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py @@ -40,7 +40,6 @@ __ENCODER_MAP_GOES_HERE__ #endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) __MACRO_OUTPUT_GOES_HERE__ - """ @@ -51,7 +50,7 @@ def _generate_keymap_table(keymap_json): lines[-1] = lines[-1] + ',' layer = map(_strip_any, layer) layer_keys = ', '.join(layer) - lines.append('\t[%s] = %s(%s)' % (layer_num, keymap_json['layout'], layer_keys)) + lines.append(' [%s] = %s(%s)' % (layer_num, keymap_json['layout'], layer_keys)) return lines @@ -61,7 +60,7 @@ def _generate_encodermap_table(keymap_json): if layer_num != 0: lines[-1] = lines[-1] + ',' encoder_keycode_txt = ', '.join([f'ENCODER_CCW_CW({_strip_any(e["ccw"])}, {_strip_any(e["cw"])})' for e in layer]) - lines.append('\t[%s] = {%s}' % (layer_num, encoder_keycode_txt)) + lines.append(' [%s] = {%s}' % (layer_num, encoder_keycode_txt)) return lines diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 674bb54be2..2b3d6f4049 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -156,7 +156,7 @@ def test_json2c(): * edit it directly. */ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -\t[0] = LAYOUT_ortho_1x1(KC_A) + [0] = LAYOUT_ortho_1x1(KC_A) }; #if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) @@ -168,7 +168,6 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - """ @@ -195,7 +194,7 @@ def test_json2c_stdin(): * edit it directly. */ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -\t[0] = LAYOUT_ortho_1x1(KC_A) + [0] = LAYOUT_ortho_1x1(KC_A) }; #if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) @@ -207,7 +206,6 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - """ diff --git a/lib/python/qmk/tests/test_qmk_keymap.py b/lib/python/qmk/tests/test_qmk_keymap.py index b4b8f4bbe0..bec3f4006c 100644 --- a/lib/python/qmk/tests/test_qmk_keymap.py +++ b/lib/python/qmk/tests/test_qmk_keymap.py @@ -31,7 +31,7 @@ def test_generate_c_pytest_basic(): * edit it directly. */ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -\t[0] = LAYOUT(KC_A) + [0] = LAYOUT(KC_A) }; #if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) @@ -41,7 +41,6 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { #endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) - """ -- cgit v1.2.3 From 783f97ff32de1d6febceb09f46dfa624e4fc56ec Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Mon, 12 Aug 2024 13:29:05 +0100 Subject: Remove handling of keyboard level keymap templates (#24234) --- lib/python/qmk/keymap.py | 39 ++------------------------------- lib/python/qmk/tests/test_qmk_keymap.py | 10 --------- 2 files changed, 2 insertions(+), 47 deletions(-) (limited to 'lib/python/qmk/tests/test_qmk_keymap.py') diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index 8c09cc51dc..f3505d324e 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py @@ -125,41 +125,6 @@ def _generate_macros_function(keymap_json): return macro_txt -def template_json(keyboard): - """Returns a `keymap.json` template for a keyboard. - - If a template exists in `keyboards//templates/keymap.json` that text will be used instead of an empty dictionary. - - Args: - keyboard - The keyboard to return a template for. - """ - template_file = Path('keyboards/%s/templates/keymap.json' % keyboard) - template = {'keyboard': keyboard} - if template_file.exists(): - template.update(json.load(template_file.open(encoding='utf-8'))) - - return template - - -def template_c(keyboard): - """Returns a `keymap.c` template for a keyboard. - - If a template exists in `keyboards//templates/keymap.c` that text will be used instead of an empty dictionary. - - Args: - keyboard - The keyboard to return a template for. - """ - template_file = Path('keyboards/%s/templates/keymap.c' % keyboard) - if template_file.exists(): - template = template_file.read_text(encoding='utf-8') - else: - template = DEFAULT_KEYMAP_C - - return template - - def _strip_any(keycode): """Remove ANY() from a keycode. """ @@ -278,7 +243,7 @@ def generate_json(keymap, keyboard, layout, layers, macros=None): macros A sequence of strings containing macros to implement for this keyboard. """ - new_keymap = template_json(keyboard) + new_keymap = {'keyboard': keyboard} new_keymap['keymap'] = keymap new_keymap['layout'] = layout new_keymap['layers'] = layers @@ -305,7 +270,7 @@ def generate_c(keymap_json): macros A sequence of strings containing macros to implement for this keyboard. """ - new_keymap = template_c(keymap_json['keyboard']) + new_keymap = DEFAULT_KEYMAP_C layer_txt = _generate_keymap_table(keymap_json) keymap = '\n'.join(layer_txt) new_keymap = new_keymap.replace('__KEYMAP_GOES_HERE__', keymap) diff --git a/lib/python/qmk/tests/test_qmk_keymap.py b/lib/python/qmk/tests/test_qmk_keymap.py index bec3f4006c..7482848eff 100644 --- a/lib/python/qmk/tests/test_qmk_keymap.py +++ b/lib/python/qmk/tests/test_qmk_keymap.py @@ -1,16 +1,6 @@ import qmk.keymap -def test_template_c_pytest_basic(): - templ = qmk.keymap.template_c('handwired/pytest/basic') - assert templ == qmk.keymap.DEFAULT_KEYMAP_C - - -def test_template_json_pytest_basic(): - templ = qmk.keymap.template_json('handwired/pytest/basic') - assert templ == {'keyboard': 'handwired/pytest/basic'} - - def test_generate_c_pytest_basic(): keymap_json = { 'keyboard': 'handwired/pytest/basic', -- cgit v1.2.3