Skip to content

Commit

Permalink
Fix CLI incorrectly following DEFAULT_FOLDER (qmk#12529)
Browse files Browse the repository at this point in the history
* Attempt to sort out incorrectly following DEFAULT_FOLDER.

* Fix CI checks.

* qmk pyformat
  • Loading branch information
tzarc authored Apr 25, 2021
1 parent 0c50a9e commit b88498b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/python/qmk/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ def list_keyboards():
kb_wildcard = os.path.join(base_path, "**", "rules.mk")
paths = [path for path in glob(kb_wildcard, recursive=True) if 'keymaps' not in path]

return sorted(map(_find_name, paths))
return sorted(set(map(resolve_keyboard, map(_find_name, paths))))


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):
Expand All @@ -106,8 +115,7 @@ def config_h(keyboard):
"""
config = {}
cur_dir = Path('keyboards')
rules = rules_mk(keyboard)
keyboard = Path(rules['DEFAULT_FOLDER'] if 'DEFAULT_FOLDER' in rules else keyboard)
keyboard = Path(resolve_keyboard(keyboard))

for dir in keyboard.parts:
cur_dir = cur_dir / dir
Expand All @@ -125,13 +133,10 @@ def rules_mk(keyboard):
Returns:
a dictionary representing the content of the entire rules.mk tree for a keyboard
"""
keyboard = Path(keyboard)
cur_dir = Path('keyboards')
keyboard = Path(resolve_keyboard(keyboard))
rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')

if 'DEFAULT_FOLDER' in rules:
keyboard = Path(rules['DEFAULT_FOLDER'])

for i, dir in enumerate(keyboard.parts):
cur_dir = cur_dir / dir
rules = parse_rules_mk_file(cur_dir / 'rules.mk', rules)
Expand Down

0 comments on commit b88498b

Please sign in to comment.