summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate/api.py
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2022-02-27 11:28:51 +0000
committerGitHub <noreply@github.com>2022-02-27 12:28:51 +0100
commite4a6afa369ca695be97dc3ba96fe129a1c24456e (patch)
treeeccad47500dd145ec2070b3956ed7a5395f9bdcd /lib/python/qmk/cli/generate/api.py
parent8f457ada3a253993106e63c18e01987a7957403e (diff)
Rework generate-api CLI command to use .build directory (#16441)
Diffstat (limited to 'lib/python/qmk/cli/generate/api.py')
-rwxr-xr-xlib/python/qmk/cli/generate/api.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py
index 285bd90eb5..0596b3f22b 100755
--- a/lib/python/qmk/cli/generate/api.py
+++ b/lib/python/qmk/cli/generate/api.py
@@ -1,7 +1,7 @@
1"""This script automates the generation of the QMK API data. 1"""This script automates the generation of the QMK API data.
2""" 2"""
3from pathlib import Path 3from pathlib import Path
4from shutil import copyfile 4import shutil
5import json 5import json
6 6
7from milc import cli 7from milc import cli
@@ -12,28 +12,42 @@ from qmk.json_encoders import InfoJSONEncoder
12from qmk.json_schema import json_load 12from qmk.json_schema import json_load
13from qmk.keyboard import find_readme, list_keyboards 13from qmk.keyboard import find_readme, list_keyboards
14 14
15TEMPLATE_PATH = Path('data/templates/api/')
16BUILD_API_PATH = Path('.build/api_data/')
17
15 18
16@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.") 19@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.")
20@cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the list of keyboards based on partial name matches the supplied value. May be passed multiple times.")
17@cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True) 21@cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True)
18def generate_api(cli): 22def generate_api(cli):
19 """Generates the QMK API data. 23 """Generates the QMK API data.
20 """ 24 """
21 api_data_dir = Path('api_data') 25 if BUILD_API_PATH.exists():
22 v1_dir = api_data_dir / 'v1' 26 shutil.rmtree(BUILD_API_PATH)
27
28 shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH)
29
30 v1_dir = BUILD_API_PATH / 'v1'
23 keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything 31 keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything
24 keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets 32 keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets
25 keyboard_aliases_file = v1_dir / 'keyboard_aliases.json' # A list of historical keyboard names and their new name 33 keyboard_aliases_file = v1_dir / 'keyboard_aliases.json' # A list of historical keyboard names and their new name
26 keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization 34 keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization
27 usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target 35 usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target
28 36
29 if not api_data_dir.exists(): 37 # Filter down when required
30 api_data_dir.mkdir() 38 keyboard_list = list_keyboards()
39 if cli.args.filter:
40 kb_list = []
41 for keyboard_name in keyboard_list:
42 if any(i in keyboard_name for i in cli.args.filter):
43 kb_list.append(keyboard_name)
44 keyboard_list = kb_list
31 45
32 kb_all = {} 46 kb_all = {}
33 usb_list = {} 47 usb_list = {}
34 48
35 # Generate and write keyboard specific JSON files 49 # Generate and write keyboard specific JSON files
36 for keyboard_name in list_keyboards(): 50 for keyboard_name in keyboard_list:
37 kb_all[keyboard_name] = info_json(keyboard_name) 51 kb_all[keyboard_name] = info_json(keyboard_name)
38 keyboard_dir = v1_dir / 'keyboards' / keyboard_name 52 keyboard_dir = v1_dir / 'keyboards' / keyboard_name
39 keyboard_info = keyboard_dir / 'info.json' 53 keyboard_info = keyboard_dir / 'info.json'
@@ -47,7 +61,7 @@ def generate_api(cli):
47 cli.log.debug('Wrote file %s', keyboard_info) 61 cli.log.debug('Wrote file %s', keyboard_info)
48 62
49 if keyboard_readme_src: 63 if keyboard_readme_src:
50 copyfile(keyboard_readme_src, keyboard_readme) 64 shutil.copyfile(keyboard_readme_src, keyboard_readme)
51 cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) 65 cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme)
52 66
53 if 'usb' in kb_all[keyboard_name]: 67 if 'usb' in kb_all[keyboard_name]: