diff options
Diffstat (limited to 'lib/python/qmk')
-rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index d662e14e00..11d4616199 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -43,7 +43,7 @@ def _resolve_keycode_specs(output_folder): overall = load_spec(version) output_file = output_folder / f'constants/keycodes_{version}.json' - output_file.write_text(json.dumps(overall, indent=4), encoding='utf-8') + output_file.write_text(json.dumps(overall), encoding='utf-8') for lang in list_languages(): for version in list_versions(lang): @@ -64,7 +64,7 @@ def _filtered_copy(src, dst): data = json_load(src) dst = dst.with_suffix('.json') - dst.write_text(json.dumps(data, indent=4), encoding='utf-8') + dst.write_text(json.dumps(data), encoding='utf-8') return dst return shutil.copy2(src, dst) @@ -111,29 +111,44 @@ def generate_api(cli): # Generate and write keyboard specific JSON files for keyboard_name in keyboard_list: - kb_all[keyboard_name] = info_json(keyboard_name) - - # Populate the list of JSON keymaps - for keymap in list_keymaps(keyboard_name, c=False, fullpath=True): - kb_all[keyboard_name]['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'} + kb_json = info_json(keyboard_name) + kb_all[keyboard_name] = kb_json keyboard_dir = v1_dir / 'keyboards' / keyboard_name keyboard_info = keyboard_dir / 'info.json' keyboard_readme = keyboard_dir / 'readme.md' keyboard_readme_src = find_readme(keyboard_name) + # Populate the list of JSON keymaps + for keymap in list_keymaps(keyboard_name, c=False, fullpath=True): + kb_json['keymaps'][keymap.name] = { + # TODO: deprecate 'url' as consumer needs to know its potentially hjson + 'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json', + + # Instead consumer should grab from API and not repo directly + 'path': (keymap / 'keymap.json').as_posix(), + } + keyboard_dir.mkdir(parents=True, exist_ok=True) - keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all[keyboard_name]}}) + keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}}) if not cli.args.dry_run: - keyboard_info.write_text(keyboard_json) + keyboard_info.write_text(keyboard_json, encoding='utf-8') cli.log.debug('Wrote file %s', keyboard_info) if keyboard_readme_src: shutil.copyfile(keyboard_readme_src, keyboard_readme) cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) - if 'usb' in kb_all[keyboard_name]: - usb = kb_all[keyboard_name]['usb'] + # resolve keymaps as json + for keymap in kb_json['keymaps']: + keymap_hjson = kb_json['keymaps'][keymap]['path'] + keymap_json = v1_dir / keymap_hjson + keymap_json.parent.mkdir(parents=True, exist_ok=True) + keymap_json.write_text(json.dumps(json_load(Path(keymap_hjson))), encoding='utf-8') + cli.log.debug('Wrote keymap %s', keymap_json) + + if 'usb' in kb_json: + usb = kb_json['usb'] if 'vid' in usb and usb['vid'] not in usb_list: usb_list[usb['vid']] = {} @@ -166,9 +181,9 @@ def generate_api(cli): constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}) if not cli.args.dry_run: - keyboard_all_file.write_text(keyboard_all_json) - usb_file.write_text(usb_json) - keyboard_list_file.write_text(keyboard_list_json) - keyboard_aliases_file.write_text(keyboard_aliases_json) - keyboard_metadata_file.write_text(keyboard_metadata_json) - constants_metadata_file.write_text(constants_metadata_json) + keyboard_all_file.write_text(keyboard_all_json, encoding='utf-8') + usb_file.write_text(usb_json, encoding='utf-8') + keyboard_list_file.write_text(keyboard_list_json, encoding='utf-8') + keyboard_aliases_file.write_text(keyboard_aliases_json, encoding='utf-8') + keyboard_metadata_file.write_text(keyboard_metadata_json, encoding='utf-8') + constants_metadata_file.write_text(constants_metadata_json, encoding='utf-8') |