diff options
author | Joel Challis <git@zvecr.com> | 2022-08-06 07:14:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-06 16:14:29 +1000 |
commit | 897403c4a71080469b8c11fc87e0e145ffe3837a (patch) | |
tree | edaf919a687f0f908b534b5a5d74e3a0432741c7 | |
parent | ec5186f0f9e2d1910331785f1410be5892058ee4 (diff) |
Publish data as part of API generation (#17020)
-rw-r--r-- | .github/workflows/api.yml | 3 | ||||
-rw-r--r-- | .github/workflows/develop_api.yml | 3 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 37 |
3 files changed, 29 insertions, 14 deletions
diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml index 9d850080a6..dd3fbdaa92 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/api.yml @@ -7,6 +7,9 @@ on: paths: - 'keyboards/**' - 'layouts/community/**' + - 'lib/python/**' + - 'data/**' + - '.github/workflows/api.yml' workflow_dispatch: jobs: diff --git a/.github/workflows/develop_api.yml b/.github/workflows/develop_api.yml index ebc1b545b7..194305e730 100644 --- a/.github/workflows/develop_api.yml +++ b/.github/workflows/develop_api.yml @@ -7,6 +7,9 @@ on: paths: - 'keyboards/**' - 'layouts/community/**' + - 'lib/python/**' + - 'data/**' + - '.github/workflows/develop_api.yml' workflow_dispatch: jobs: diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 0596b3f22b..8d8ca3cd41 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -12,21 +12,30 @@ from qmk.json_encoders import InfoJSONEncoder from qmk.json_schema import json_load from qmk.keyboard import find_readme, list_keyboards -TEMPLATE_PATH = Path('data/templates/api/') +DATA_PATH = Path('data') +TEMPLATE_PATH = DATA_PATH / 'templates/api/' BUILD_API_PATH = Path('.build/api_data/') +def _filtered_keyboard_list(): + """Perform basic filtering of list_keyboards + """ + keyboard_list = list_keyboards() + if cli.args.filter: + kb_list = [] + for keyboard_name in keyboard_list: + if any(i in keyboard_name for i in cli.args.filter): + kb_list.append(keyboard_name) + keyboard_list = kb_list + return keyboard_list + + @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.") @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.") -@cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True) +@cli.subcommand('Generate QMK API data', hidden=False if cli.config.user.developer else True) def generate_api(cli): """Generates the QMK API data. """ - if BUILD_API_PATH.exists(): - shutil.rmtree(BUILD_API_PATH) - - shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH) - v1_dir = BUILD_API_PATH / 'v1' keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets @@ -34,14 +43,14 @@ def generate_api(cli): keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target + if BUILD_API_PATH.exists(): + shutil.rmtree(BUILD_API_PATH) + + shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH) + shutil.copytree(DATA_PATH, v1_dir) + # Filter down when required - keyboard_list = list_keyboards() - if cli.args.filter: - kb_list = [] - for keyboard_name in keyboard_list: - if any(i in keyboard_name for i in cli.args.filter): - kb_list.append(keyboard_name) - keyboard_list = kb_list + keyboard_list = _filtered_keyboard_list() kb_all = {} usb_list = {} |