summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli/generate
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-05-10 11:18:44 -0700
committerGitHub <noreply@github.com>2021-05-10 11:18:44 -0700
commita3e7f3e7c58ee98596ead5c213f3a9ed8340cd80 (patch)
treeef0cb85205fad7562045f23caa8a16384e43bbb5 /lib/python/qmk/cli/generate
parent66ed80ad3a0edecd9d7abbef71fc2a6e3e59b541 (diff)
Improve our CI tests (#11476)
* add a test and dry-run to qmk generate-api * add a dry-run to qmk pyformat * Add a --dry-run to qmk cformat * reverse the order of nose2 and flake8 tests * run CI test against cformat and pyformat * fix programming errors * tweak job name * fix argument * refine the files we select * fix stack trace in --ci * make cformat exit clean * fix c file extensions * decouple CI from pyformat * remove --ci arg * make ci happy * use the environment var instead * change output to text * fix log message * replace tabs
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rwxr-xr-xlib/python/qmk/cli/generate/api.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py
index 70019428f0..8ab7522a76 100755
--- a/lib/python/qmk/cli/generate/api.py
+++ b/lib/python/qmk/cli/generate/api.py
@@ -13,6 +13,7 @@ from qmk.json_schema import json_load
from qmk.keyboard import list_keyboards
+@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.")
@cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True)
def generate_api(cli):
"""Generates the QMK API data.
@@ -40,10 +41,14 @@ def generate_api(cli):
keyboard_readme_src = Path('keyboards') / keyboard_name / 'readme.md'
keyboard_dir.mkdir(parents=True, exist_ok=True)
- keyboard_info.write_text(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_all[keyboard_name]}})
+ if not cli.args.dry_run:
+ keyboard_info.write_text(keyboard_json)
+ cli.log.debug('Wrote file %s', keyboard_info)
- if keyboard_readme_src.exists():
- copyfile(keyboard_readme_src, keyboard_readme)
+ if keyboard_readme_src.exists():
+ 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']
@@ -57,20 +62,26 @@ def generate_api(cli):
if 'vid' in usb and 'pid' in usb:
usb_list[usb['vid']][usb['pid']][keyboard_name] = usb
- # Write the global JSON files
- keyboard_all_file.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, cls=InfoJSONEncoder))
- usb_file.write_text(json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, cls=InfoJSONEncoder))
-
+ # Generate data for the global files
keyboard_list = sorted(kb_all)
- keyboard_list_file.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, cls=InfoJSONEncoder))
-
keyboard_aliases = json_load(Path('data/mappings/keyboard_aliases.json'))
- keyboard_aliases_file.write_text(json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, cls=InfoJSONEncoder))
-
keyboard_metadata = {
'last_updated': current_datetime(),
'keyboards': keyboard_list,
'keyboard_aliases': keyboard_aliases,
'usb': usb_list,
}
- keyboard_metadata_file.write_text(json.dumps(keyboard_metadata, cls=InfoJSONEncoder))
+
+ # 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)
+
+ 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)