Fix CLI community detection (#19562)

This commit is contained in:
Joel Challis 2023-01-11 01:38:35 +00:00 committed by GitHub
parent f4a25bcfaf
commit 20474ae232
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 33 deletions

View file

@ -10,6 +10,7 @@ from qmk.datetime import current_datetime
from qmk.info import info_json
from qmk.json_encoders import InfoJSONEncoder
from qmk.json_schema import json_load
from qmk.keymap import list_keymaps
from qmk.keyboard import find_readme, list_keyboards
from qmk.keycodes import load_spec, list_versions, list_languages
@ -111,6 +112,11 @@ def generate_api(cli):
# Generate and write keyboard specific JSON files
for keyboard_name in keyboard_list:
kb_all[keyboard_name] = info_json(keyboard_name)
# Populate the list of JSON keymaps
for keymap in list_keymaps(keyboard_name, c=False, fullpath=True):
kb_all[keyboard_name]['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'}
keyboard_dir = v1_dir / 'keyboards' / keyboard_name
keyboard_info = keyboard_dir / 'info.json'
keyboard_readme = keyboard_dir / 'readme.md'

View file

@ -10,7 +10,6 @@ from qmk.constants import CHIBIOS_PROCESSORS, LUFA_PROCESSORS, VUSB_PROCESSORS
from qmk.c_parse import find_layouts, parse_config_h_file, find_led_config
from qmk.json_schema import deep_update, json_load, validate
from qmk.keyboard import config_h, rules_mk
from qmk.keymap import list_keymaps, locate_keymap
from qmk.commands import parse_configurator_json
from qmk.makefile import parse_rules_mk_file
from qmk.math import compute
@ -99,10 +98,6 @@ def info_json(keyboard):
'maintainer': 'qmk',
}
# Populate the list of JSON keymaps
for keymap in list_keymaps(keyboard, c=False, fullpath=True):
info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'}
# Populate layout data
layouts, aliases = _search_keyboard_h(keyboard)
@ -872,6 +867,9 @@ def find_info_json(keyboard):
def keymap_json_config(keyboard, keymap):
"""Extract keymap level config
"""
# TODO: resolve keymap.py and info.py circular dependencies
from qmk.keymap import locate_keymap
keymap_folder = locate_keymap(keyboard, keymap).parent
km_info_json = parse_configurator_json(keymap_folder / 'keymap.json')
@ -881,6 +879,9 @@ def keymap_json_config(keyboard, keymap):
def keymap_json(keyboard, keymap):
"""Generate the info.json data for a specific keymap.
"""
# TODO: resolve keymap.py and info.py circular dependencies
from qmk.keymap import locate_keymap
keymap_folder = locate_keymap(keyboard, keymap).parent
# Files to scan

View file

@ -12,8 +12,9 @@ from pygments.token import Token
from pygments import lex
import qmk.path
from qmk.keyboard import find_keyboard_from_dir, rules_mk, keyboard_folder
from qmk.keyboard import find_keyboard_from_dir, keyboard_folder
from qmk.errors import CppError
from qmk.info import info_json
# The `keymap.c` template to use when a keyboard doesn't have its own
DEFAULT_KEYMAP_C = """#include QMK_KEYBOARD_H
@ -374,11 +375,11 @@ def locate_keymap(keyboard, keymap):
return keymap_path
# Check community layouts as a fallback
rules = rules_mk(keyboard)
info = info_json(keyboard)
if "LAYOUTS" in rules:
for layout in rules["LAYOUTS"].split():
community_layout = Path('layouts/community') / layout / keymap
for community_parent in Path('layouts').glob('*/'):
for layout in info.get("community_layouts", []):
community_layout = community_parent / layout / keymap
if community_layout.exists():
if (community_layout / 'keymap.json').exists():
return community_layout / 'keymap.json'
@ -408,11 +409,8 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa
Returns:
a sorted list of valid keymap names.
"""
# parse all the rules.mk files for the keyboard
rules = rules_mk(keyboard)
names = set()
if rules is not None:
keyboards_dir = Path('keyboards')
kb_path = keyboards_dir / keyboard
@ -429,10 +427,12 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa
kb_path = kb_path.parent
# if community layouts are supported, get them
if "LAYOUTS" in rules:
for layout in rules["LAYOUTS"].split():
cl_path = Path('layouts/community') / layout
# Check community layouts as a fallback
info = info_json(keyboard)
for community_parent in Path('layouts').glob('*/'):
for layout in info.get("community_layouts", []):
cl_path = community_parent / layout
if cl_path.is_dir():
for keymap in cl_path.iterdir():
if is_keymap_dir(keymap, c, json, additional_files):