From 33110be4a81db49135f2f2347baeb13d4a87d2c3 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 24 Jun 2020 15:57:27 +1000 Subject: [PATCH 1/8] Improve LAYOUT macro searching --- lib/python/qmk/info.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index de7632e3784e..9a3ba8e1ffaf 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -99,21 +99,28 @@ def _extract_rules_mk(info_data): return info_data +def _search_keyboard_h(layouts, path): + current_path = Path('keyboards/') + for directory in path.parts: + current_path = current_path / directory + keyboard_h = '%s.h' % (directory,) + keyboard_h_path = current_path / keyboard_h + if keyboard_h_path.exists(): + layouts.update(find_layouts(keyboard_h_path)) + + def _find_all_layouts(keyboard): """Looks for layout macros associated with this keyboard. """ layouts = {} rules = rules_mk(keyboard) - keyboard_path = Path(rules.get('DEFAULT_FOLDER', keyboard)) # Pull in all layouts defined in the standard files - current_path = Path('keyboards/') - for directory in keyboard_path.parts: - current_path = current_path / directory - keyboard_h = '%s.h' % (directory,) - keyboard_h_path = current_path / keyboard_h - if keyboard_h_path.exists(): - layouts.update(find_layouts(keyboard_h_path)) + _search_keyboard_h(layouts, Path(keyboard)) + + if not layouts: + # Search in DEFAULT_FOLDER next, if we didn't get any hits + _search_keyboard_h(layouts, Path(rules.get('DEFAULT_FOLDER', keyboard))) if not layouts: # If we didn't find any layouts above we widen our search. This is error From 7cfb45c8364f9cddde85464103b896f1c9443af5 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 25 Jun 2020 09:35:31 +1000 Subject: [PATCH 2/8] Apply suggestions from code review Co-authored-by: Zach White --- lib/python/qmk/info.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 9a3ba8e1ffaf..40001c415355 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -108,19 +108,20 @@ def _search_keyboard_h(layouts, path): if keyboard_h_path.exists(): layouts.update(find_layouts(keyboard_h_path)) + return layouts + def _find_all_layouts(keyboard): """Looks for layout macros associated with this keyboard. """ - layouts = {} rules = rules_mk(keyboard) # Pull in all layouts defined in the standard files - _search_keyboard_h(layouts, Path(keyboard)) + layouts = _search_keyboard_h(Path(keyboard)) if not layouts: # Search in DEFAULT_FOLDER next, if we didn't get any hits - _search_keyboard_h(layouts, Path(rules.get('DEFAULT_FOLDER', keyboard))) + layouts = _search_keyboard_h(layouts, Path(rules.get('DEFAULT_FOLDER', keyboard))) if not layouts: # If we didn't find any layouts above we widen our search. This is error From d098e9aee535af009bb8194e6fb972f8a2d7c0c2 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Thu, 25 Jun 2020 09:43:45 +1000 Subject: [PATCH 3/8] Adjust signature --- lib/python/qmk/info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 40001c415355..75be98d5de98 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -99,8 +99,9 @@ def _extract_rules_mk(info_data): return info_data -def _search_keyboard_h(layouts, path): +def _search_keyboard_h(path): current_path = Path('keyboards/') + layouts = {} for directory in path.parts: current_path = current_path / directory keyboard_h = '%s.h' % (directory,) From 0044320e2c2149c04c7614f7dfab23710287e72e Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 1 Jul 2020 00:48:07 +1000 Subject: [PATCH 4/8] Try to copy the makefile's handling of DEFAULT_FOLDER --- lib/python/qmk/info.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 75be98d5de98..9289c58a1a51 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -9,6 +9,7 @@ from qmk.constants import ARM_PROCESSORS, AVR_PROCESSORS, VUSB_PROCESSORS from qmk.c_parse import find_layouts from qmk.keyboard import config_h, rules_mk +from qmk.makefile import parse_rules_mk_file from qmk.math import compute @@ -115,14 +116,18 @@ def _search_keyboard_h(path): def _find_all_layouts(keyboard): """Looks for layout macros associated with this keyboard. """ - rules = rules_mk(keyboard) + cur_dir = Path('keyboards') + rules = parse_rules_mk_file(cur_dir / Path(keyboard) / 'rules.mk') + default_folder = rules.get('DEFAULT_FOLDER', '') # Pull in all layouts defined in the standard files - layouts = _search_keyboard_h(Path(keyboard)) + if not default_folder == keyboard: + rules = parse_rules_mk_file(cur_dir / Path(default_folder) / 'rules.mk', rules) + default_folder = rules.get('DEFAULT_FOLDER', keyboard) - if not layouts: - # Search in DEFAULT_FOLDER next, if we didn't get any hits - layouts = _search_keyboard_h(layouts, Path(rules.get('DEFAULT_FOLDER', keyboard))) + keyboard = default_folder + + layouts = _search_keyboard_h(Path(keyboard)) if not layouts: # If we didn't find any layouts above we widen our search. This is error From dffa6dc2484a412e3c71454ca639e80beb609507 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 1 Jul 2020 03:18:18 +1000 Subject: [PATCH 5/8] Move it further up, into `info_json()` --- lib/python/qmk/info.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 9289c58a1a51..c4a0bd9f657d 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -23,7 +23,17 @@ def info_json(keyboard): 'maintainer': 'qmk', } - for layout_name, layout_json in _find_all_layouts(keyboard).items(): + cur_dir = Path('keyboards') + rules = parse_rules_mk_file(cur_dir / Path(keyboard) / 'rules.mk') + default_folder = rules.get('DEFAULT_FOLDER', '') + + if not default_folder == keyboard: + rules = parse_rules_mk_file(cur_dir / Path(default_folder) / 'rules.mk', rules) + default_folder = rules.get('DEFAULT_FOLDER', keyboard) + + keyboard = default_folder + + for layout_name, layout_json in _find_all_layouts(keyboard, rules).items(): if not layout_name.startswith('LAYOUT_kc'): info_data['layouts'][layout_name] = layout_json @@ -113,20 +123,9 @@ def _search_keyboard_h(path): return layouts -def _find_all_layouts(keyboard): +def _find_all_layouts(keyboard, rules): """Looks for layout macros associated with this keyboard. """ - cur_dir = Path('keyboards') - rules = parse_rules_mk_file(cur_dir / Path(keyboard) / 'rules.mk') - default_folder = rules.get('DEFAULT_FOLDER', '') - - # Pull in all layouts defined in the standard files - if not default_folder == keyboard: - rules = parse_rules_mk_file(cur_dir / Path(default_folder) / 'rules.mk', rules) - default_folder = rules.get('DEFAULT_FOLDER', keyboard) - - keyboard = default_folder - layouts = _search_keyboard_h(Path(keyboard)) if not layouts: From f62494ced11902b10f4925025ead75f74d8367e0 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Thu, 2 Jul 2020 00:13:39 +1000 Subject: [PATCH 6/8] Move it even further up so that keyboard_folder is correct --- lib/python/qmk/info.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index c4a0bd9f657d..d5a81c087878 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -16,13 +16,6 @@ def info_json(keyboard): """Generate the info.json data for a specific keyboard. """ - info_data = { - 'keyboard_name': str(keyboard), - 'keyboard_folder': str(keyboard), - 'layouts': {}, - 'maintainer': 'qmk', - } - cur_dir = Path('keyboards') rules = parse_rules_mk_file(cur_dir / Path(keyboard) / 'rules.mk') default_folder = rules.get('DEFAULT_FOLDER', '') @@ -33,6 +26,13 @@ def info_json(keyboard): keyboard = default_folder + info_data = { + 'keyboard_name': str(keyboard), + 'keyboard_folder': str(keyboard), + 'layouts': {}, + 'maintainer': 'qmk', + } + for layout_name, layout_json in _find_all_layouts(keyboard, rules).items(): if not layout_name.startswith('LAYOUT_kc'): info_data['layouts'][layout_name] = layout_json From 0ab0108e16dc7c9569243ab942b9f2f740df17fc Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 4 Oct 2020 23:41:15 +1100 Subject: [PATCH 7/8] Update lib/python/qmk/info.py Co-authored-by: Zach White --- lib/python/qmk/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index d5a81c087878..f35b4e75ae7d 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -17,7 +17,7 @@ def info_json(keyboard): """Generate the info.json data for a specific keyboard. """ cur_dir = Path('keyboards') - rules = parse_rules_mk_file(cur_dir / Path(keyboard) / 'rules.mk') + rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') default_folder = rules.get('DEFAULT_FOLDER', '') if not default_folder == keyboard: From cad55b253fb4b8f72a07a9a9377ebee10234845e Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 5 Oct 2020 03:43:45 +1100 Subject: [PATCH 8/8] Update lib/python/qmk/info.py Co-authored-by: Zach White --- lib/python/qmk/info.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index f35b4e75ae7d..c780a0ab2329 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -18,13 +18,9 @@ def info_json(keyboard): """ cur_dir = Path('keyboards') rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') - default_folder = rules.get('DEFAULT_FOLDER', '') - - if not default_folder == keyboard: - rules = parse_rules_mk_file(cur_dir / Path(default_folder) / 'rules.mk', rules) - default_folder = rules.get('DEFAULT_FOLDER', keyboard) - - keyboard = default_folder + if 'DEFAULT_FOLDER' in rules: + keyboard = rules['DEFAULT_FOLDER'] + rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk', rules) info_data = { 'keyboard_name': str(keyboard),