diff options
Diffstat (limited to 'lib/python/qmk')
-rwxr-xr-x | lib/python/qmk/cli/generate/make_dependencies.py | 3 | ||||
-rw-r--r-- | lib/python/qmk/cli/new/keyboard.py | 2 | ||||
-rw-r--r-- | lib/python/qmk/info.py | 15 | ||||
-rw-r--r-- | lib/python/qmk/keyboard.py | 10 | ||||
-rw-r--r-- | lib/python/qmk/path.py | 3 |
5 files changed, 24 insertions, 9 deletions
diff --git a/lib/python/qmk/cli/generate/make_dependencies.py b/lib/python/qmk/cli/generate/make_dependencies.py index 9b695e907d..331132a20f 100755 --- a/lib/python/qmk/cli/generate/make_dependencies.py +++ b/lib/python/qmk/cli/generate/make_dependencies.py @@ -18,10 +18,11 @@ from qmk.path import normpath, FileType @cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') @cli.subcommand('Generates the list of dependencies associated with a keyboard build and its generated files.', hidden=True) def generate_make_dependencies(cli): - """Generates the list of dependent info.json, rules.mk, and config.h files for a keyboard. + """Generates the list of dependent config files for a keyboard. """ interesting_files = [ 'info.json', + 'keyboard.json', 'rules.mk', 'post_rules.mk', 'config.h', diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py index cb50acf8bb..700afc96a6 100644 --- a/lib/python/qmk/cli/new/keyboard.py +++ b/lib/python/qmk/cli/new/keyboard.py @@ -251,7 +251,7 @@ def new_keyboard(cli): # merge in infos community_info = Path(COMMUNITY / f'{default_layout}/info.json') - augment_community_info(community_info, keyboard(kb_name) / community_info.name) + augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json') cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}') cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.") diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 13588abdb8..2449284668 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -863,7 +863,17 @@ def unknown_processor_rules(info_data, rules): def merge_info_jsons(keyboard, info_data): """Return a merged copy of all the info.json files for a keyboard. """ - for info_file in find_info_json(keyboard): + config_files = find_info_json(keyboard) + + # keyboard.json can only exist at the deepest part of the tree + keyboard_json_count = 0 + for index, info_file in enumerate(config_files): + if Path(info_file).name == 'keyboard.json': + keyboard_json_count += 1 + if index != 0 or keyboard_json_count > 1: + _log_error(info_data, f'Invalid keyboard.json location detected: {info_file}.') + + for info_file in config_files: # Load and validate the JSON data new_info_data = json_load(info_file) @@ -921,7 +931,7 @@ def find_info_json(keyboard): base_path = Path('keyboards') keyboard_path = base_path / keyboard keyboard_parent = keyboard_path.parent - info_jsons = [keyboard_path / 'info.json'] + info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json'] # Add DEFAULT_FOLDER before parents, if present rules = rules_mk(keyboard) @@ -933,6 +943,7 @@ def find_info_json(keyboard): if keyboard_parent == base_path: break info_jsons.append(keyboard_parent / 'info.json') + info_jsons.append(keyboard_parent / 'keyboard.json') keyboard_parent = keyboard_parent.parent # Return a list of the info.json files that actually exist diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index b56505d649..0fcc2e868d 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py @@ -166,9 +166,9 @@ def keyboard_folder_or_all(keyboard): def _find_name(path): - """Determine the keyboard name by stripping off the base_path and rules.mk. + """Determine the keyboard name by stripping off the base_path and filename. """ - return path.replace(base_path, "").replace(os.path.sep + "rules.mk", "") + return path.replace(base_path, "").rsplit(os.path.sep, 1)[0] def keyboard_completer(prefix, action, parser, parsed_args): @@ -181,8 +181,10 @@ def list_keyboards(resolve_defaults=True): """Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER. """ # We avoid pathlib here because this is performance critical code. - kb_wildcard = os.path.join(base_path, "**", "rules.mk") - paths = [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path] + paths = [] + for marker in ['rules.mk', 'keyboard.json']: + kb_wildcard = os.path.join(base_path, "**", marker) + paths += [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path] found = map(_find_name, paths) if resolve_defaults: diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index 74364ee04b..85a8f48c4f 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -15,8 +15,9 @@ def is_keyboard(keyboard_name): if keyboard_name: keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name rules_mk = keyboard_path / 'rules.mk' + keyboard_json = keyboard_path / 'keyboard.json' - return rules_mk.exists() + return rules_mk.exists() or keyboard_json.exists() def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])): |