summaryrefslogtreecommitdiff
path: root/lib/python/qmk
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-08-15 13:30:58 -0700
committerGitHub <noreply@github.com>2021-08-16 06:30:58 +1000
commitfd340f8957055d74b26a5ddc490253fcc8a3a2f7 (patch)
tree4bef92368860d748bfd36e45af90f9bc72870353 /lib/python/qmk
parentf56c202fb31ad7cdfdbcb4083dd5dad54d2b508f (diff)
Defer the expensive search for layout macros until info.json has been processed (#14007)
* defer the expensive search for layout macros until info.json has been processed * fixup names
Diffstat (limited to 'lib/python/qmk')
-rw-r--r--lib/python/qmk/info.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index 7f9907a50f..858fbab335 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -49,7 +49,7 @@ def info_json(keyboard):
info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'}
# Populate layout data
- layouts, aliases = _find_all_layouts(info_data, keyboard)
+ layouts, aliases = _search_keyboard_h(keyboard)
if aliases:
info_data['layout_aliases'] = aliases
@@ -78,6 +78,9 @@ def info_json(keyboard):
# Make sure we have at least one layout
if not info_data.get('layouts'):
+ _find_missing_layouts(info_data, keyboard)
+
+ if not info_data.get('layouts'):
_log_error(info_data, 'No LAYOUTs defined! Need at least one layout defined in the keyboard.h or info.json.')
# Filter out any non-existing community layouts
@@ -417,12 +420,13 @@ def _merge_layouts(info_data, new_info_data):
return info_data
-def _search_keyboard_h(path):
+def _search_keyboard_h(keyboard):
+ keyboard = Path(keyboard)
current_path = Path('keyboards/')
aliases = {}
layouts = {}
- for directory in path.parts:
+ for directory in keyboard.parts:
current_path = current_path / directory
keyboard_h = '%s.h' % (directory,)
keyboard_h_path = current_path / keyboard_h
@@ -437,27 +441,28 @@ def _search_keyboard_h(path):
return layouts, aliases
-def _find_all_layouts(info_data, keyboard):
- """Looks for layout macros associated with this keyboard.
- """
- layouts, aliases = _search_keyboard_h(Path(keyboard))
+def _find_missing_layouts(info_data, keyboard):
+ """Looks for layout macros when they aren't found other places.
- if not layouts:
- # If we don't find any layouts from info.json or keyboard.h we widen our search. This is error prone which is why we want to encourage people to follow the standard above.
- info_data['parse_warnings'].append('%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard))
+ If we don't find any layouts from info.json or keyboard.h we widen our search. This is error prone which is why we want to encourage people to follow the standard above.
+ """
+ _log_warning(info_data, '%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard))
- for file in glob('keyboards/%s/*.h' % keyboard):
- if file.endswith('.h'):
- these_layouts, these_aliases = find_layouts(file)
+ for file in glob('keyboards/%s/*.h' % keyboard):
+ these_layouts, these_aliases = find_layouts(file)
- if these_layouts:
- layouts.update(these_layouts)
+ if these_layouts:
+ for layout_name, layout_json in these_layouts.items():
+ if not layout_name.startswith('LAYOUT_kc'):
+ layout_json['c_macro'] = True
+ info_data['layouts'][layout_name] = layout_json
- for alias, alias_text in these_aliases.items():
- if alias_text in layouts:
- aliases[alias] = alias_text
+ for alias, alias_text in these_aliases.items():
+ if alias_text in these_layouts:
+ if 'layout_aliases' not in info_data:
+ info_data['layout_aliases'] = {}
- return layouts, aliases
+ info_data['layout_aliases'][alias] = alias_text
def _log_error(info_data, message):