Browse Source

Deprecate DEFAULT_FOLDER

deprecate_default_folder
zvecr 1 month ago
parent
commit
44531604bb
7 changed files with 23 additions and 41 deletions
  1. +4
    -13
      Makefile
  2. +1
    -0
      data/mappings/info_rules.hjson
  3. +1
    -5
      lib/python/qmk/cli/ci/validate_aliases.py
  4. +1
    -2
      lib/python/qmk/cli/list/keyboards.py
  5. +2
    -2
      lib/python/qmk/cli/migrate.py
  6. +0
    -11
      lib/python/qmk/info.py
  7. +14
    -8
      lib/python/qmk/keyboard.py

+ 4
- 13
Makefile View File

@ -138,7 +138,7 @@ define PARSE_RULE
$$(eval $$(call PARSE_TEST))
# If the rule starts with the name of a known keyboard, then continue
# the parsing from PARSE_KEYBOARD
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(shell $(QMK_BIN) list-keyboards --no-resolve-defaults)),true)
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(shell $(QMK_BIN) list-keyboards)),true)
KEYBOARD_RULE=$$(MATCHED_ITEM)
$$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM)))
else
@ -172,15 +172,6 @@ define PARSE_KEYBOARD
# KEYBOARD_FOLDERS := $$(subst /, , $(CURRENT_KB))
DEFAULT_FOLDER := $$(CURRENT_KB)
# We assume that every rules.mk will contain the full default value
$$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/rules.mk)
ifneq ($$(DEFAULT_FOLDER),$$(CURRENT_KB))
$$(eval include $(ROOT_DIR)/keyboards/$$(DEFAULT_FOLDER)/rules.mk)
endif
CURRENT_KB := $$(DEFAULT_FOLDER)
# 5/4/3/2/1
KEYBOARD_FOLDER_PATH_1 := $$(CURRENT_KB)
KEYBOARD_FOLDER_PATH_2 := $$(patsubst %/,%,$$(dir $$(KEYBOARD_FOLDER_PATH_1)))
@ -242,7 +233,7 @@ endef
# if we are going to compile all keyboards, match the rest of the rule
# for each of them
define PARSE_ALL_KEYBOARDS
$$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(shell $(QMK_BIN) list-keyboards --no-resolve-defaults)))
$$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(shell $(QMK_BIN) list-keyboards)))
endef
# Prints a list of all known keymaps for the given keyboard
@ -434,7 +425,7 @@ git-submodules: git-submodule
.PHONY: list-keyboards
list-keyboards:
$(QMK_BIN) list-keyboards --no-resolve-defaults | tr '\n' ' '
$(QMK_BIN) list-keyboards | tr '\n' ' '
.PHONY: list-tests
list-tests:
@ -442,7 +433,7 @@ list-tests:
.PHONY: generate-keyboards-file
generate-keyboards-file:
$(QMK_BIN) list-keyboards --no-resolve-defaults
$(QMK_BIN) list-keyboards
.PHONY: clean
clean:


+ 1
- 0
data/mappings/info_rules.hjson View File

@ -50,5 +50,6 @@
// Items we want flagged in lint
"CTPC": {"info_key": "_deprecated.ctpc", "deprecated": true, "replace_with": "CONVERT_TO=proton_c"},
"CONVERT_TO_PROTON_C": {"info_key": "_deprecated.ctpc", "deprecated": true, "replace_with": "CONVERT_TO=proton_c"},
"DEFAULT_FOLDER": {"info_key": "_deprecated.default_folder", "deprecated": true}
"VIAL_ENABLE": {"info_key": "_invalid.vial", "invalid": true}
}

+ 1
- 5
lib/python/qmk/cli/ci/validate_aliases.py View File

@ -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


+ 1
- 2
lib/python/qmk/cli/list/keyboards.py View File

@ -5,10 +5,9 @@ from milc import cli
import qmk.keyboard
@cli.argument('--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)

+ 2
- 2
lib/python/qmk/cli/migrate.py View File

@ -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 = []


+ 0
- 11
lib/python/qmk/info.py View File

@ -189,12 +189,6 @@ def _validate(keyboard, info_data):
def info_json(keyboard):
"""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),
@ -947,11 +941,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:


+ 14
- 8
lib/python/qmk/keyboard.py View File

@ -72,7 +72,15 @@ base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep
@lru_cache(maxsize=1)
def keyboard_alias_definitions():
return json_load(Path('data/mappings/keyboard_aliases.hjson'))
data = json_load(Path('data/mappings/keyboard_aliases.hjson'))
# Add fake entries to maintain DEFAULT_FOLDER logic for CLI
for kb in list_keyboards(False):
res = _resolve_keyboard(kb)
if res != kb:
data[kb] = {'target': res}
return data
def is_all_keyboards(keyboard):
@ -129,8 +137,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}')
@ -142,7 +148,7 @@ def keyboard_aliases(keyboard):
Includes the keyboard itself.
"""
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
aliases = keyboard_alias_definitions()
if keyboard in aliases:
keyboard = aliases[keyboard].get('target', keyboard)
@ -188,13 +194,13 @@ def list_keyboards(resolve_defaults=True):
found = map(_find_name, paths)
if resolve_defaults:
found = map(resolve_keyboard, found)
found = map(_resolve_keyboard, found)
return sorted(set(found))
@lru_cache(maxsize=None)
def resolve_keyboard(keyboard):
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']:
@ -214,7 +220,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
@ -233,7 +239,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):


Loading…
Cancel
Save