keyboard stuff
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rework generate-api CLI command to use .build directory (#16441)

authored by

Joel Challis and committed by
GitHub
e4a6afa3 8f457ada

+24 -11
+1 -1
.github/workflows/api.yml
··· 35 35 AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }} 36 36 AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_KEY }} 37 37 AWS_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com 38 - SOURCE_DIR: 'api_data' 38 + SOURCE_DIR: '.build/api_data'
+1 -1
.github/workflows/develop_api.yml
··· 35 35 AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }} 36 36 AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_KEY }} 37 37 AWS_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com 38 - SOURCE_DIR: 'api_data' 38 + SOURCE_DIR: '.build/api_data'
-1
api_data/_config.yml
··· 1 - theme: jekyll-theme-cayman
api_data/readme.md data/templates/api/readme.md
+21 -7
lib/python/qmk/cli/generate/api.py
··· 1 1 """This script automates the generation of the QMK API data. 2 2 """ 3 3 from pathlib import Path 4 - from shutil import copyfile 4 + import shutil 5 5 import json 6 6 7 7 from milc import cli ··· 12 12 from qmk.json_schema import json_load 13 13 from qmk.keyboard import find_readme, list_keyboards 14 14 15 + TEMPLATE_PATH = Path('data/templates/api/') 16 + BUILD_API_PATH = Path('.build/api_data/') 17 + 15 18 16 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 21 @cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True) 18 22 def generate_api(cli): 19 23 """Generates the QMK API data. 20 24 """ 21 - api_data_dir = Path('api_data') 22 - v1_dir = api_data_dir / 'v1' 25 + if BUILD_API_PATH.exists(): 26 + shutil.rmtree(BUILD_API_PATH) 27 + 28 + shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH) 29 + 30 + v1_dir = BUILD_API_PATH / 'v1' 23 31 keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything 24 32 keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets 25 33 keyboard_aliases_file = v1_dir / 'keyboard_aliases.json' # A list of historical keyboard names and their new name 26 34 keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization 27 35 usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target 28 36 29 - if not api_data_dir.exists(): 30 - api_data_dir.mkdir() 37 + # Filter down when required 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 46 kb_all = {} 33 47 usb_list = {} 34 48 35 49 # Generate and write keyboard specific JSON files 36 - for keyboard_name in list_keyboards(): 50 + for keyboard_name in keyboard_list: 37 51 kb_all[keyboard_name] = info_json(keyboard_name) 38 52 keyboard_dir = v1_dir / 'keyboards' / keyboard_name 39 53 keyboard_info = keyboard_dir / 'info.json' ··· 47 61 cli.log.debug('Wrote file %s', keyboard_info) 48 62 49 63 if keyboard_readme_src: 50 - copyfile(keyboard_readme_src, keyboard_readme) 64 + shutil.copyfile(keyboard_readme_src, keyboard_readme) 51 65 cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) 52 66 53 67 if 'usb' in kb_all[keyboard_name]:
+1 -1
lib/python/qmk/tests/test_cli_commands.py
··· 232 232 233 233 234 234 def test_generate_api(): 235 - result = check_subcommand('generate-api', '--dry-run') 235 + result = check_subcommand('generate-api', '--dry-run', '--filter', 'handwired/pytest') 236 236 check_returncode(result) 237 237 238 238