diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 014587cb168..6c19b21ef58 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -9,7 +9,6 @@ from milc import cli from qmk.datetime import current_datetime from qmk.info import info_json -from qmk.json_encoders import InfoJSONEncoder from qmk.json_schema import json_load from qmk.keymap import list_keymaps from qmk.keyboard import find_readme, list_keyboards @@ -45,14 +44,14 @@ 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), encoding='utf-8') + output_file.write_text(json.dumps(overall, separators=(',', ':')), encoding='utf-8') for lang in list_languages(): for version in list_versions(lang): overall = load_spec(version, lang) output_file = output_folder / f'constants/keycodes_{lang}_{version}.json' - output_file.write_text(json.dumps(overall, indent=4), encoding='utf-8') + output_file.write_text(json.dumps(overall, separators=(',', ':')), encoding='utf-8') # Purge files consumed by 'load_spec' shutil.rmtree(output_folder / 'constants/keycodes/') @@ -66,7 +65,7 @@ def _filtered_copy(src, dst): data = json_load(src) dst = dst.with_suffix('.json') - dst.write_text(json.dumps(data), encoding='utf-8') + dst.write_text(json.dumps(data, separators=(',', ':')), encoding='utf-8') return dst if dst.suffix == '.jsonschema': @@ -154,7 +153,7 @@ def generate_api(cli): } keyboard_dir.mkdir(parents=True, exist_ok=True) - keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}}) + keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}}, separators=(',', ':')) if not cli.args.dry_run: keyboard_info.write_text(keyboard_json, encoding='utf-8') cli.log.debug('Wrote file %s', keyboard_info) @@ -168,7 +167,7 @@ def generate_api(cli): 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') + keymap_json.write_text(json.dumps(json_load(Path(keymap_hjson)), separators=(',', ':')), encoding='utf-8') cli.log.debug('Wrote keymap %s', keymap_json) if 'usb' in kb_json: @@ -198,12 +197,12 @@ def generate_api(cli): _resolve_xap_specs(v1_dir / 'xap') # Write the global JSON files - keyboard_all_json = json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, cls=InfoJSONEncoder) - usb_json = json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, cls=InfoJSONEncoder) - keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, cls=InfoJSONEncoder) - keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, cls=InfoJSONEncoder) - keyboard_metadata_json = json.dumps(keyboard_metadata, cls=InfoJSONEncoder) - constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}) + keyboard_all_json = json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, separators=(',', ':')) + usb_json = json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, separators=(',', ':')) + keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, separators=(',', ':')) + keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, separators=(',', ':')) + keyboard_metadata_json = json.dumps(keyboard_metadata, separators=(',', ':')) + constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}, separators=(',', ':')) if not cli.args.dry_run: keyboard_all_file.write_text(keyboard_all_json, encoding='utf-8')