diff options
-rw-r--r-- | lib/python/qmk/info.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 7f9907a50..858fbab33 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py | |||
@@ -49,7 +49,7 @@ def info_json(keyboard): | |||
49 | info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'} | 49 | info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'} |
50 | 50 | ||
51 | # Populate layout data | 51 | # Populate layout data |
52 | layouts, aliases = _find_all_layouts(info_data, keyboard) | 52 | layouts, aliases = _search_keyboard_h(keyboard) |
53 | 53 | ||
54 | if aliases: | 54 | if aliases: |
55 | info_data['layout_aliases'] = aliases | 55 | info_data['layout_aliases'] = aliases |
@@ -78,6 +78,9 @@ def info_json(keyboard): | |||
78 | 78 | ||
79 | # Make sure we have at least one layout | 79 | # Make sure we have at least one layout |
80 | if not info_data.get('layouts'): | 80 | if not info_data.get('layouts'): |
81 | _find_missing_layouts(info_data, keyboard) | ||
82 | |||
83 | if not info_data.get('layouts'): | ||
81 | _log_error(info_data, 'No LAYOUTs defined! Need at least one layout defined in the keyboard.h or info.json.') | 84 | _log_error(info_data, 'No LAYOUTs defined! Need at least one layout defined in the keyboard.h or info.json.') |
82 | 85 | ||
83 | # Filter out any non-existing community layouts | 86 | # Filter out any non-existing community layouts |
@@ -417,12 +420,13 @@ def _merge_layouts(info_data, new_info_data): | |||
417 | return info_data | 420 | return info_data |
418 | 421 | ||
419 | 422 | ||
420 | def _search_keyboard_h(path): | 423 | def _search_keyboard_h(keyboard): |
424 | keyboard = Path(keyboard) | ||
421 | current_path = Path('keyboards/') | 425 | current_path = Path('keyboards/') |
422 | aliases = {} | 426 | aliases = {} |
423 | layouts = {} | 427 | layouts = {} |
424 | 428 | ||
425 | for directory in path.parts: | 429 | for directory in keyboard.parts: |
426 | current_path = current_path / directory | 430 | current_path = current_path / directory |
427 | keyboard_h = '%s.h' % (directory,) | 431 | keyboard_h = '%s.h' % (directory,) |
428 | keyboard_h_path = current_path / keyboard_h | 432 | keyboard_h_path = current_path / keyboard_h |
@@ -437,27 +441,28 @@ def _search_keyboard_h(path): | |||
437 | return layouts, aliases | 441 | return layouts, aliases |
438 | 442 | ||
439 | 443 | ||
440 | def _find_all_layouts(info_data, keyboard): | 444 | def _find_missing_layouts(info_data, keyboard): |
441 | """Looks for layout macros associated with this keyboard. | 445 | """Looks for layout macros when they aren't found other places. |
442 | """ | ||
443 | layouts, aliases = _search_keyboard_h(Path(keyboard)) | ||
444 | 446 | ||
445 | if not layouts: | 447 | 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. |
446 | # 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. | 448 | """ |
447 | info_data['parse_warnings'].append('%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard)) | 449 | _log_warning(info_data, '%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard)) |
448 | 450 | ||
449 | for file in glob('keyboards/%s/*.h' % keyboard): | 451 | for file in glob('keyboards/%s/*.h' % keyboard): |
450 | if file.endswith('.h'): | 452 | these_layouts, these_aliases = find_layouts(file) |
451 | these_layouts, these_aliases = find_layouts(file) | ||
452 | 453 | ||
453 | if these_layouts: | 454 | if these_layouts: |
454 | layouts.update(these_layouts) | 455 | for layout_name, layout_json in these_layouts.items(): |
456 | if not layout_name.startswith('LAYOUT_kc'): | ||
457 | layout_json['c_macro'] = True | ||
458 | info_data['layouts'][layout_name] = layout_json | ||
455 | 459 | ||
456 | for alias, alias_text in these_aliases.items(): | 460 | for alias, alias_text in these_aliases.items(): |
457 | if alias_text in layouts: | 461 | if alias_text in these_layouts: |
458 | aliases[alias] = alias_text | 462 | if 'layout_aliases' not in info_data: |
463 | info_data['layout_aliases'] = {} | ||
459 | 464 | ||
460 | return layouts, aliases | 465 | info_data['layout_aliases'][alias] = alias_text |
461 | 466 | ||
462 | 467 | ||
463 | def _log_error(info_data, message): | 468 | def _log_error(info_data, message): |