diff options
Diffstat (limited to 'lib/python')
| -rw-r--r-- | lib/python/qmk/cli/ci/validate_aliases.py | 6 | ||||
| -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/info.py | 11 | ||||
| -rw-r--r-- | lib/python/qmk/keyboard.py | 34 | ||||
| -rw-r--r-- | lib/python/qmk/path.py | 6 |
7 files changed, 15 insertions, 51 deletions
diff --git a/lib/python/qmk/cli/ci/validate_aliases.py b/lib/python/qmk/cli/ci/validate_aliases.py index 7f781d4397..8b062dbe56 100644 --- a/lib/python/qmk/cli/ci/validate_aliases.py +++ b/lib/python/qmk/cli/ci/validate_aliases.py | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | """ | 2 | """ |
| 3 | from milc import cli | 3 | from milc import cli |
| 4 | 4 | ||
| 5 | from qmk.keyboard import resolve_keyboard, keyboard_folder, keyboard_alias_definitions | 5 | from qmk.keyboard import keyboard_folder, keyboard_alias_definitions |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | def _safe_keyboard_folder(target): | 8 | def _safe_keyboard_folder(target): |
| @@ -17,10 +17,6 @@ def _target_keyboard_exists(target): | |||
| 17 | if not target: | 17 | if not target: |
| 18 | return False | 18 | return False |
| 19 | 19 | ||
| 20 | # If the target directory existed but there was no rules.mk or rules.mk was incorrectly parsed, then we can't build it. | ||
| 21 | if not resolve_keyboard(target): | ||
| 22 | return False | ||
| 23 | |||
| 24 | # If the target directory exists but it itself has an invalid alias or invalid rules.mk, then we can't build it either. | 20 | # If the target directory exists but it itself has an invalid alias or invalid rules.mk, then we can't build it either. |
| 25 | if not _safe_keyboard_folder(target): | 21 | if not _safe_keyboard_folder(target): |
| 26 | return False | 22 | return False |
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 | |||
| 5 | import qmk.keyboard | 5 | import qmk.keyboard |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | @cli.argument('--no-resolve-defaults', arg_only=True, action='store_false', help='Ignore any "DEFAULT_FOLDER" within keyboards rules.mk') | ||
| 9 | @cli.subcommand("List the keyboards currently defined within QMK") | 8 | @cli.subcommand("List the keyboards currently defined within QMK") |
| 10 | def list_keyboards(cli): | 9 | def list_keyboards(cli): |
| 11 | """List the keyboards currently defined within QMK | 10 | """List the keyboards currently defined within QMK |
| 12 | """ | 11 | """ |
| 13 | for keyboard_name in qmk.keyboard.list_keyboards(cli.args.no_resolve_defaults): | 12 | for keyboard_name in qmk.keyboard.list_keyboards(): |
| 14 | print(keyboard_name) | 13 | 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 | |||
| 6 | 6 | ||
| 7 | from milc import cli | 7 | from milc import cli |
| 8 | 8 | ||
| 9 | from qmk.keyboard import keyboard_completer, keyboard_folder, resolve_keyboard | 9 | from qmk.keyboard import keyboard_completer, keyboard_folder |
| 10 | from qmk.info import info_json, find_info_json | 10 | from qmk.info import info_json, find_info_json |
| 11 | from qmk.json_encoders import InfoJSONEncoder | 11 | from qmk.json_encoders import InfoJSONEncoder |
| 12 | from qmk.json_schema import json_load | 12 | from qmk.json_schema import json_load |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | def _candidate_files(keyboard): | 15 | def _candidate_files(keyboard): |
| 16 | kb_dir = Path(resolve_keyboard(keyboard)) | 16 | kb_dir = Path(keyboard) |
| 17 | 17 | ||
| 18 | cur_dir = Path('keyboards') | 18 | cur_dir = Path('keyboards') |
| 19 | files = [] | 19 | 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 | |||
| 5 | 5 | ||
| 6 | @cli.argument('--allow-unknown', arg_only=True, action='store_true', help="Return original if rule is not a valid keyboard.") | 6 | @cli.argument('--allow-unknown', arg_only=True, action='store_true', help="Return original if rule is not a valid keyboard.") |
| 7 | @cli.argument('keyboard', arg_only=True, help='The keyboard\'s name') | 7 | @cli.argument('keyboard', arg_only=True, help='The keyboard\'s name') |
| 8 | @cli.subcommand('Resolve DEFAULT_FOLDER and any keyboard_aliases for provided rule') | 8 | @cli.subcommand('Resolve any keyboard_aliases for provided rule') |
| 9 | def resolve_alias(cli): | 9 | def resolve_alias(cli): |
| 10 | try: | 10 | try: |
| 11 | print(keyboard_folder(cli.args.keyboard)) | 11 | print(keyboard_folder(cli.args.keyboard)) |
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index d95fd3d799..db8a02d132 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py | |||
| @@ -223,12 +223,6 @@ def _validate(keyboard, info_data): | |||
| 223 | def info_json(keyboard, force_layout=None): | 223 | def info_json(keyboard, force_layout=None): |
| 224 | """Generate the info.json data for a specific keyboard. | 224 | """Generate the info.json data for a specific keyboard. |
| 225 | """ | 225 | """ |
| 226 | cur_dir = Path('keyboards') | ||
| 227 | root_rules_mk = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') | ||
| 228 | |||
| 229 | if 'DEFAULT_FOLDER' in root_rules_mk: | ||
| 230 | keyboard = root_rules_mk['DEFAULT_FOLDER'] | ||
| 231 | |||
| 232 | info_data = { | 226 | info_data = { |
| 233 | 'keyboard_name': str(keyboard), | 227 | 'keyboard_name': str(keyboard), |
| 234 | 'keyboard_folder': str(keyboard), | 228 | 'keyboard_folder': str(keyboard), |
| @@ -1005,11 +999,6 @@ def find_info_json(keyboard): | |||
| 1005 | keyboard_parent = keyboard_path.parent | 999 | keyboard_parent = keyboard_path.parent |
| 1006 | info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json'] | 1000 | info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json'] |
| 1007 | 1001 | ||
| 1008 | # Add DEFAULT_FOLDER before parents, if present | ||
| 1009 | rules = rules_mk(keyboard) | ||
| 1010 | if 'DEFAULT_FOLDER' in rules: | ||
| 1011 | info_jsons.append(Path(rules['DEFAULT_FOLDER']) / 'info.json') | ||
| 1012 | |||
| 1013 | # Add in parent folders for least specific | 1002 | # Add in parent folders for least specific |
| 1014 | for _ in range(5): | 1003 | for _ in range(5): |
| 1015 | if keyboard_parent == base_path: | 1004 | 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(): | |||
| 99 | keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1 | 99 | keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1 |
| 100 | current_path = current_path.parents[keymap_index] | 100 | current_path = current_path.parents[keymap_index] |
| 101 | 101 | ||
| 102 | current_path = resolve_keyboard(current_path) | ||
| 103 | |||
| 104 | if qmk.path.is_keyboard(current_path): | 102 | if qmk.path.is_keyboard(current_path): |
| 105 | return str(current_path) | 103 | return str(current_path) |
| 106 | 104 | ||
| @@ -121,7 +119,7 @@ def find_readme(keyboard): | |||
| 121 | def keyboard_folder(keyboard): | 119 | def keyboard_folder(keyboard): |
| 122 | """Returns the actual keyboard folder. | 120 | """Returns the actual keyboard folder. |
| 123 | 121 | ||
| 124 | This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard. | 122 | This checks aliases to resolve the actual path for a keyboard. |
| 125 | """ | 123 | """ |
| 126 | aliases = keyboard_alias_definitions() | 124 | aliases = keyboard_alias_definitions() |
| 127 | 125 | ||
| @@ -131,8 +129,6 @@ def keyboard_folder(keyboard): | |||
| 131 | if keyboard == last_keyboard: | 129 | if keyboard == last_keyboard: |
| 132 | break | 130 | break |
| 133 | 131 | ||
| 134 | keyboard = resolve_keyboard(keyboard) | ||
| 135 | |||
| 136 | if not qmk.path.is_keyboard(keyboard): | 132 | if not qmk.path.is_keyboard(keyboard): |
| 137 | raise ValueError(f'Invalid keyboard: {keyboard}') | 133 | raise ValueError(f'Invalid keyboard: {keyboard}') |
| 138 | 134 | ||
| @@ -158,7 +154,7 @@ def keyboard_aliases(keyboard): | |||
| 158 | def keyboard_folder_or_all(keyboard): | 154 | def keyboard_folder_or_all(keyboard): |
| 159 | """Returns the actual keyboard folder. | 155 | """Returns the actual keyboard folder. |
| 160 | 156 | ||
| 161 | This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard. | 157 | This checks aliases to resolve the actual path for a keyboard. |
| 162 | If the supplied argument is "all", it returns an AllKeyboards object. | 158 | If the supplied argument is "all", it returns an AllKeyboards object. |
| 163 | """ | 159 | """ |
| 164 | if keyboard == 'all': | 160 | if keyboard == 'all': |
| @@ -179,32 +175,18 @@ def keyboard_completer(prefix, action, parser, parsed_args): | |||
| 179 | return list_keyboards() | 175 | return list_keyboards() |
| 180 | 176 | ||
| 181 | 177 | ||
| 182 | def list_keyboards(resolve_defaults=True): | 178 | def list_keyboards(): |
| 183 | """Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER. | 179 | """Returns a list of all keyboards |
| 184 | """ | 180 | """ |
| 185 | # We avoid pathlib here because this is performance critical code. | 181 | # We avoid pathlib here because this is performance critical code. |
| 186 | paths = [] | 182 | kb_wildcard = os.path.join(base_path, "**", 'keyboard.json') |
| 187 | for marker in ['rules.mk', 'keyboard.json']: | 183 | paths = [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path] |
| 188 | kb_wildcard = os.path.join(base_path, "**", marker) | ||
| 189 | paths += [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path] | ||
| 190 | 184 | ||
| 191 | found = map(_find_name, paths) | 185 | found = map(_find_name, paths) |
| 192 | if resolve_defaults: | ||
| 193 | found = map(resolve_keyboard, found) | ||
| 194 | 186 | ||
| 195 | return sorted(set(found)) | 187 | return sorted(set(found)) |
| 196 | 188 | ||
| 197 | 189 | ||
| 198 | @lru_cache(maxsize=None) | ||
| 199 | def resolve_keyboard(keyboard): | ||
| 200 | cur_dir = Path('keyboards') | ||
| 201 | rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') | ||
| 202 | while 'DEFAULT_FOLDER' in rules and keyboard != rules['DEFAULT_FOLDER']: | ||
| 203 | keyboard = rules['DEFAULT_FOLDER'] | ||
| 204 | rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') | ||
| 205 | return keyboard | ||
| 206 | |||
| 207 | |||
| 208 | def config_h(keyboard): | 190 | def config_h(keyboard): |
| 209 | """Parses all the config.h files for a keyboard. | 191 | """Parses all the config.h files for a keyboard. |
| 210 | 192 | ||
| @@ -216,7 +198,7 @@ def config_h(keyboard): | |||
| 216 | """ | 198 | """ |
| 217 | config = {} | 199 | config = {} |
| 218 | cur_dir = Path('keyboards') | 200 | cur_dir = Path('keyboards') |
| 219 | keyboard = Path(resolve_keyboard(keyboard)) | 201 | keyboard = Path(keyboard) |
| 220 | 202 | ||
| 221 | for dir in keyboard.parts: | 203 | for dir in keyboard.parts: |
| 222 | cur_dir = cur_dir / dir | 204 | cur_dir = cur_dir / dir |
| @@ -235,7 +217,7 @@ def rules_mk(keyboard): | |||
| 235 | a dictionary representing the content of the entire rules.mk tree for a keyboard | 217 | a dictionary representing the content of the entire rules.mk tree for a keyboard |
| 236 | """ | 218 | """ |
| 237 | cur_dir = Path('keyboards') | 219 | cur_dir = Path('keyboards') |
| 238 | keyboard = Path(resolve_keyboard(keyboard)) | 220 | keyboard = Path(keyboard) |
| 239 | rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') | 221 | rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk') |
| 240 | 222 | ||
| 241 | for i, dir in enumerate(keyboard.parts): | 223 | for i, dir in enumerate(keyboard.parts): |
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): | |||
| 21 | if Path(keyboard_name).is_absolute(): | 21 | if Path(keyboard_name).is_absolute(): |
| 22 | return False | 22 | return False |
| 23 | 23 | ||
| 24 | keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name | 24 | keyboard_json = QMK_FIRMWARE / 'keyboards' / keyboard_name / 'keyboard.json' |
| 25 | rules_mk = keyboard_path / 'rules.mk' | ||
| 26 | keyboard_json = keyboard_path / 'keyboard.json' | ||
| 27 | 25 | ||
| 28 | return rules_mk.exists() or keyboard_json.exists() | 26 | return keyboard_json.exists() |
| 29 | 27 | ||
| 30 | 28 | ||
| 31 | def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])): | 29 | def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])): |
