diff --git a/lib/python/qmk/cli/lint.py b/lib/python/qmk/cli/lint.py index 8a128ce6d2c4..c5a013e18e5a 100644 --- a/lib/python/qmk/cli/lint.py +++ b/lib/python/qmk/cli/lint.py @@ -22,15 +22,10 @@ def _list_defaultish_keymaps(kb): """Return default like keymaps for a given keyboard """ - defaultish = ['ansi', 'iso'] + keymaps = set(list_keymaps(kb, include_userspace=False, include_community=False)) - # This is only here to flag it as "testable", so it doesn't fly under the radar during PR - defaultish.extend(INVALID_KM_NAMES) - - keymaps = set() - for x in list_keymaps(kb, include_userspace=False): - if x in defaultish or x.startswith('default'): - keymaps.add(x) + # Ensure that at least a 'default' keymap always exists + keymaps.add('default') return keymaps @@ -360,6 +355,11 @@ def lint(cli): cli.print_help() return False + # milc config handling of user.keymap breaks running lint without keymap argument + # so we have to disable that while still allowing a default to be set with lint.keymap + if 'keymap' not in cli.config_source.lint.keys() and cli.config.lint.keymap: + cli.config.lint.keymap = None + if isinstance(cli.config.lint.keyboard, str): # if provided via config - string not array keyboard_list = [cli.config.lint.keyboard] @@ -375,12 +375,12 @@ def lint(cli): # Determine keymaps to also check if cli.args.keymap == 'all': keymaps = list_keymaps(kb) + elif cli.args.keymap: + keymaps = {cli.args.keymap} elif cli.config.lint.keymap: keymaps = {cli.config.lint.keymap} else: keymaps = _list_defaultish_keymaps(kb) - # Ensure that at least a 'default' keymap always exists - keymaps.add('default') ok = True diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index 36a821ebda3d..c9e99a01b588 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py @@ -381,7 +381,7 @@ def is_keymap_target(keyboard, keymap): return False -def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=False, include_userspace=True): +def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=False, include_userspace=True, include_community=True): """List the available keymaps for a keyboard. Args: @@ -403,6 +403,9 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa include_userspace When set to True, also search userspace for available keymaps + include_community + When set to True, also search community layouts folder for available keymaps + Returns: a sorted list of valid keymap names. """ @@ -426,21 +429,22 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa kb_path = kb_path.parent - # Check community layouts as a fallback - info = info_json(keyboard) - - community_parents = list(Path('layouts').glob('*/')) - if has_userspace and (Path(QMK_USERSPACE) / "layouts").exists(): - community_parents.append(Path(QMK_USERSPACE) / "layouts") - - for community_parent in community_parents: - 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): - keymap = keymap if fullpath else keymap.name - names.add(keymap) + if include_community: + # Check community layouts as a fallback + info = info_json(keyboard) + + community_parents = list(Path('layouts').glob('*/')) + if has_userspace and (Path(QMK_USERSPACE) / "layouts").exists(): + community_parents.append(Path(QMK_USERSPACE) / "layouts") + + for community_parent in community_parents: + 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): + keymap = keymap if fullpath else keymap.name + names.add(keymap) return sorted(names)