Browse Source

Update lint to check all keymaps within the repo (#25970)

Joel Challis 4 months ago
parent
commit
f7a77c8b70
2 changed files with 30 additions and 26 deletions
  1. 10 10
      lib/python/qmk/cli/lint.py
  2. 20 16
      lib/python/qmk/keymap.py

+ 10 - 10
lib/python/qmk/cli/lint.py

@@ -22,15 +22,10 @@ INVALID_KM_NAMES = ['via', 'vial']
 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
 
@@ -366,6 +361,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]
@@ -381,12 +381,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
 

+ 20 - 16
lib/python/qmk/keymap.py

@@ -389,7 +389,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:
@@ -411,6 +411,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.
     """
@@ -434,21 +437,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)