diff options
Diffstat (limited to 'lib/python')
-rw-r--r-- | lib/python/qmk/cli/ci/validate_aliases.py | 27 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/config_h.py | 15 | ||||
-rw-r--r-- | lib/python/qmk/cli/list/keyboards.py | 3 | ||||
-rw-r--r-- | lib/python/qmk/cli/migrate.py | 4 | ||||
-rw-r--r-- | lib/python/qmk/cli/resolve_alias.py | 2 | ||||
-rw-r--r-- | lib/python/qmk/flashers.py | 6 | ||||
-rw-r--r-- | lib/python/qmk/info.py | 31 | ||||
-rw-r--r-- | lib/python/qmk/keyboard.py | 34 | ||||
-rw-r--r-- | lib/python/qmk/keymap.py | 15 | ||||
-rw-r--r-- | lib/python/qmk/path.py | 6 |
10 files changed, 64 insertions, 79 deletions
diff --git a/lib/python/qmk/cli/ci/validate_aliases.py b/lib/python/qmk/cli/ci/validate_aliases.py index 7f781d4397..4f2fe6c941 100644 --- a/lib/python/qmk/cli/ci/validate_aliases.py +++ b/lib/python/qmk/cli/ci/validate_aliases.py @@ -2,7 +2,7 @@ """ from milc import cli -from qmk.keyboard import resolve_keyboard, keyboard_folder, keyboard_alias_definitions +from qmk.keyboard import keyboard_folder, keyboard_alias_definitions def _safe_keyboard_folder(target): @@ -17,10 +17,6 @@ def _target_keyboard_exists(target): if not target: return False - # If the target directory existed but there was no rules.mk or rules.mk was incorrectly parsed, then we can't build it. - if not resolve_keyboard(target): - return False - # If the target directory exists but it itself has an invalid alias or invalid rules.mk, then we can't build it either. if not _safe_keyboard_folder(target): return False @@ -29,6 +25,21 @@ def _target_keyboard_exists(target): return True +def _alias_not_self(alias): + """Check if alias points to itself, either directly or within a circular reference + """ + aliases = keyboard_alias_definitions() + + found = set() + while alias in aliases: + found.add(alias) + alias = aliases[alias].get('target', alias) + if alias in found: + return False + + return True + + @cli.subcommand('Validates the list of keyboard aliases.', hidden=True) def ci_validate_aliases(cli): aliases = keyboard_alias_definitions() @@ -36,7 +47,11 @@ def ci_validate_aliases(cli): success = True for alias in aliases.keys(): target = aliases[alias].get('target', None) - if not _target_keyboard_exists(target): + if not _alias_not_self(alias): + cli.log.error(f'Keyboard alias {alias} should not point to itself') + success = False + + elif not _target_keyboard_exists(target): cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}') success = False diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index d613f7b92c..d6d0299291 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -72,19 +72,6 @@ def generate_matrix_size(kb_info_json, config_h_lines): config_h_lines.append(generate_define('MATRIX_ROWS', kb_info_json['matrix_size']['rows'])) -def generate_matrix_masked(kb_info_json, config_h_lines): - """"Enable matrix mask if required""" - mask_required = False - - if 'matrix_grid' in kb_info_json.get('dip_switch', {}): - mask_required = True - if 'matrix_grid' in kb_info_json.get('split', {}).get('handedness', {}): - mask_required = True - - if mask_required: - config_h_lines.append(generate_define('MATRIX_MASKED')) - - def generate_config_items(kb_info_json, config_h_lines): """Iterate through the info_config map to generate basic config values. """ @@ -202,8 +189,6 @@ def generate_config_h(cli): generate_matrix_size(kb_info_json, config_h_lines) - generate_matrix_masked(kb_info_json, config_h_lines) - if 'matrix_pins' in kb_info_json: config_h_lines.append(matrix_pins(kb_info_json['matrix_pins'])) diff --git a/lib/python/qmk/cli/list/keyboards.py b/lib/python/qmk/cli/list/keyboards.py index 405b9210e4..8b6c451673 100644 --- a/lib/python/qmk/cli/list/keyboards.py +++ b/lib/python/qmk/cli/list/keyboards.py @@ -5,10 +5,9 @@ from milc import cli import qmk.keyboard [email protected]('--no-resolve-defaults', arg_only=True, action='store_false', help='Ignore any "DEFAULT_FOLDER" within keyboards rules.mk') @cli.subcommand("List the keyboards currently defined within QMK") def list_keyboards(cli): """List the keyboards currently defined within QMK """ - for keyboard_name in qmk.keyboard.list_keyboards(cli.args.no_resolve_defaults): + for keyboard_name in qmk.keyboard.list_keyboards(): print(keyboard_name) diff --git a/lib/python/qmk/cli/migrate.py b/lib/python/qmk/cli/migrate.py index 0bab5c1949..d0f195d737 100644 --- a/lib/python/qmk/cli/migrate.py +++ b/lib/python/qmk/cli/migrate.py @@ -6,14 +6,14 @@ from dotty_dict import dotty from milc import cli -from qmk.keyboard import keyboard_completer, keyboard_folder, resolve_keyboard +from qmk.keyboard import keyboard_completer, keyboard_folder from qmk.info import info_json, find_info_json from qmk.json_encoders import InfoJSONEncoder from qmk.json_schema import json_load def _candidate_files(keyboard): - kb_dir = Path(resolve_keyboard(keyboard)) + kb_dir = Path(keyboard) cur_dir = Path('keyboards') files = [] diff --git a/lib/python/qmk/cli/resolve_alias.py b/lib/python/qmk/cli/resolve_alias.py index b9ffb46618..dff2242b28 100644 --- a/lib/python/qmk/cli/resolve_alias.py +++ b/lib/python/qmk/cli/resolve_alias.py @@ -5,7 +5,7 @@ from milc import cli @cli.argument('--allow-unknown', arg_only=True, action='store_true', help="Return original if rule is not a valid keyboard.") @cli.argument('keyboard', arg_only=True, help='The keyboard\'s name') [email protected]('Resolve DEFAULT_FOLDER and any keyboard_aliases for provided rule') [email protected]('Resolve any keyboard_aliases for provided rule') def resolve_alias(cli): try: print(keyboard_folder(cli.args.keyboard)) diff --git a/lib/python/qmk/flashers.py b/lib/python/qmk/flashers.py index 2cca4941d3..22d9133d65 100644 --- a/lib/python/qmk/flashers.py +++ b/lib/python/qmk/flashers.py @@ -96,7 +96,7 @@ def _find_bootloader(): details = 'halfkay' else: details = 'qmk-hid' - elif bl in {'apm32-dfu', 'gd32v-dfu', 'kiibohd', 'stm32-dfu'}: + elif bl in {'apm32-dfu', 'at32-dfu', 'gd32v-dfu', 'kiibohd', 'stm32-dfu'}: details = (vid, pid) else: details = None @@ -176,7 +176,7 @@ def _flash_dfu_util(details, file): # kiibohd elif details[0] == '1c11' and details[1] == 'b007': cli.run(['dfu-util', '-a', '0', '-d', f'{details[0]}:{details[1]}', '-D', file], capture_output=False) - # STM32, APM32, or GD32V DFU + # STM32, APM32, AT32, or GD32V DFU else: cli.run(['dfu-util', '-a', '0', '-d', f'{details[0]}:{details[1]}', '-s', '0x08000000:leave', '-D', file], capture_output=False) @@ -226,7 +226,7 @@ def flasher(mcu, file): return (True, "Please make sure 'teensy_loader_cli' or 'hid_bootloader_cli' is available on your system.") else: return (True, "Specifying the MCU with '-m' is necessary for HalfKay/HID bootloaders!") - elif bl in {'apm32-dfu', 'gd32v-dfu', 'kiibohd', 'stm32-dfu'}: + elif bl in {'apm32-dfu', 'at32-dfu', 'gd32v-dfu', 'kiibohd', 'stm32-dfu'}: _flash_dfu_util(details, file) elif bl == 'wb32-dfu': if _flash_wb32_dfu_updater(file): diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index d95fd3d799..b4fa481b1b 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -223,12 +223,6 @@ def _validate(keyboard, info_data): def info_json(keyboard, force_layout=None): """Generate the info.json data for a specific keyboard. """ - cur_dir = Path('keyboards') - root_rules_mk = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') - - if 'DEFAULT_FOLDER' in root_rules_mk: - keyboard = root_rules_mk['DEFAULT_FOLDER'] - info_data = { 'keyboard_name': str(keyboard), 'keyboard_folder': str(keyboard), @@ -260,6 +254,7 @@ def info_json(keyboard, force_layout=None): # Ensure that we have various calculated values info_data = _matrix_size(info_data) info_data = _joystick_axis_count(info_data) + info_data = _matrix_masked(info_data) # Merge in data from <keyboard.c> info_data = _extract_led_config(info_data, str(keyboard)) @@ -836,6 +831,25 @@ def _joystick_axis_count(info_data): return info_data +def _matrix_masked(info_data): + """"Add info_data['matrix_pins.masked'] if required""" + mask_required = False + + if 'matrix_grid' in info_data.get('dip_switch', {}): + mask_required = True + if 'matrix_grid' in info_data.get('split', {}).get('handedness', {}): + mask_required = True + + if mask_required: + if 'masked' not in info_data.get('matrix_pins', {}): + if 'matrix_pins' not in info_data: + info_data['matrix_pins'] = {} + + info_data['matrix_pins']['masked'] = True + + return info_data + + def _check_matrix(info_data): """Check the matrix to ensure that row/column count is consistent. """ @@ -1005,11 +1019,6 @@ def find_info_json(keyboard): keyboard_parent = keyboard_path.parent info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json'] - # Add DEFAULT_FOLDER before parents, if present - rules = rules_mk(keyboard) - if 'DEFAULT_FOLDER' in rules: - info_jsons.append(Path(rules['DEFAULT_FOLDER']) / 'info.json') - # Add in parent folders for least specific for _ in range(5): if keyboard_parent == base_path: diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index fcf5b5b158..254dc62309 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py @@ -99,8 +99,6 @@ def find_keyboard_from_dir(): keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1 current_path = current_path.parents[keymap_index] - current_path = resolve_keyboard(current_path) - if qmk.path.is_keyboard(current_path): return str(current_path) @@ -121,7 +119,7 @@ def find_readme(keyboard): def keyboard_folder(keyboard): """Returns the actual keyboard folder. - This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard. + This checks aliases to resolve the actual path for a keyboard. """ aliases = keyboard_alias_definitions() @@ -131,8 +129,6 @@ def keyboard_folder(keyboard): if keyboard == last_keyboard: break - keyboard = resolve_keyboard(keyboard) - if not qmk.path.is_keyboard(keyboard): raise ValueError(f'Invalid keyboard: {keyboard}') @@ -158,7 +154,7 @@ def keyboard_aliases(keyboard): def keyboard_folder_or_all(keyboard): """Returns the actual keyboard folder. - This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard. + This checks aliases to resolve the actual path for a keyboard. If the supplied argument is "all", it returns an AllKeyboards object. """ if keyboard == 'all': @@ -179,32 +175,18 @@ def keyboard_completer(prefix, action, parser, parsed_args): return list_keyboards() -def list_keyboards(resolve_defaults=True): - """Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER. +def list_keyboards(): + """Returns a list of all keyboards """ # We avoid pathlib here because this is performance critical code. - paths = [] - for marker in ['rules.mk', 'keyboard.json']: - kb_wildcard = os.path.join(base_path, "**", marker) - paths += [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path] + kb_wildcard = os.path.join(base_path, "**", 'keyboard.json') + paths = [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path] found = map(_find_name, paths) - if resolve_defaults: - found = map(resolve_keyboard, found) return sorted(set(found)) -@lru_cache(maxsize=None) -def resolve_keyboard(keyboard): - cur_dir = Path('keyboards') - rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') - while 'DEFAULT_FOLDER' in rules and keyboard != rules['DEFAULT_FOLDER']: - keyboard = rules['DEFAULT_FOLDER'] - rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') - return keyboard - - def config_h(keyboard): """Parses all the config.h files for a keyboard. @@ -216,7 +198,7 @@ def config_h(keyboard): """ config = {} cur_dir = Path('keyboards') - keyboard = Path(resolve_keyboard(keyboard)) + keyboard = Path(keyboard) for dir in keyboard.parts: cur_dir = cur_dir / dir @@ -235,7 +217,7 @@ def rules_mk(keyboard): a dictionary representing the content of the entire rules.mk tree for a keyboard """ cur_dir = Path('keyboards') - keyboard = Path(resolve_keyboard(keyboard)) + keyboard = Path(keyboard) rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') for i, dir in enumerate(keyboard.parts): diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index b7138aa4a1..4cf07f59d6 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py @@ -343,24 +343,21 @@ def locate_keymap(keyboard, keymap, force_layout=None): # Check the keyboard folder first, last match wins keymap_path = '' - search_dirs = [QMK_FIRMWARE] - keyboard_dirs = [keyboard_folder(keyboard)] + search_conf = {QMK_FIRMWARE: [keyboard_folder(keyboard)]} if HAS_QMK_USERSPACE: # When we've got userspace, check there _last_ as we want them to override anything in the main repo. - search_dirs.append(QMK_USERSPACE) # We also want to search for any aliases as QMK's folder structure may have changed, with an alias, but the user # hasn't updated their keymap location yet. - keyboard_dirs.extend(keyboard_aliases(keyboard)) - keyboard_dirs = list(set(keyboard_dirs)) + search_conf[QMK_USERSPACE] = list(set([keyboard_folder(keyboard), *keyboard_aliases(keyboard)])) - for search_dir in search_dirs: + for search_dir, keyboard_dirs in search_conf.items(): for keyboard_dir in keyboard_dirs: checked_dirs = '' - for dir in keyboard_dir.split('/'): + for folder_name in keyboard_dir.split('/'): if checked_dirs: - checked_dirs = '/'.join((checked_dirs, dir)) + checked_dirs = '/'.join((checked_dirs, folder_name)) else: - checked_dirs = dir + checked_dirs = folder_name keymap_dir = Path(search_dir) / Path('keyboards') / checked_dirs / 'keymaps' diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index c47ed18362..1739689adf 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -21,11 +21,9 @@ def is_keyboard(keyboard_name): if Path(keyboard_name).is_absolute(): return False - keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name - rules_mk = keyboard_path / 'rules.mk' - keyboard_json = keyboard_path / 'keyboard.json' + keyboard_json = QMK_FIRMWARE / 'keyboards' / keyboard_name / 'keyboard.json' - return rules_mk.exists() or keyboard_json.exists() + return keyboard_json.exists() def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])): |