diff options
Diffstat (limited to 'lib/python/qmk/cli')
-rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 28 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/config_h.py | 7 | ||||
-rw-r--r-- | lib/python/qmk/cli/generate/docs.py | 7 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/rules_mk.py | 4 | ||||
-rw-r--r-- | lib/python/qmk/cli/pytest.py | 3 |
5 files changed, 35 insertions, 14 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 @@ """This script automates the generation of the QMK API data. """ from pathlib import Path -from shutil import copyfile +import shutil import json from milc import cli @@ -12,28 +12,42 @@ 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/') +BUILD_API_PATH = Path('.build/api_data/') + @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) def generate_api(cli): """Generates the QMK API data. """ - api_data_dir = Path('api_data') - v1_dir = api_data_dir / 'v1' + 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 keyboard_aliases_file = v1_dir / 'keyboard_aliases.json' # A list of historical keyboard names and their new name 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 not api_data_dir.exists(): - api_data_dir.mkdir() + # 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 kb_all = {} usb_list = {} # Generate and write keyboard specific JSON files - for keyboard_name in list_keyboards(): + for keyboard_name in keyboard_list: kb_all[keyboard_name] = info_json(keyboard_name) keyboard_dir = v1_dir / 'keyboards' / keyboard_name keyboard_info = keyboard_dir / 'info.json' @@ -47,7 +61,7 @@ def generate_api(cli): cli.log.debug('Wrote file %s', keyboard_info) if keyboard_readme_src: - copyfile(keyboard_readme_src, keyboard_readme) + shutil.copyfile(keyboard_readme_src, keyboard_readme) cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) if 'usb' in kb_all[keyboard_name]: diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index fdc76b23d4..adefdb5732 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -84,7 +84,7 @@ def generate_config_items(kb_info_json, config_h_lines): for config_key, info_dict in info_config_map.items(): info_key = info_dict['info_key'] - key_type = info_dict.get('value_type', 'str') + key_type = info_dict.get('value_type', 'raw') to_config = info_dict.get('to_config', True) if not to_config: @@ -112,6 +112,11 @@ def generate_config_items(kb_info_json, config_h_lines): config_h_lines.append(f'#ifndef {key}') config_h_lines.append(f'# define {key} {value}') config_h_lines.append(f'#endif // {key}') + elif key_type == 'str': + config_h_lines.append('') + config_h_lines.append(f'#ifndef {config_key}') + config_h_lines.append(f'# define {config_key} "{config_value}"') + config_h_lines.append(f'#endif // {config_key}') elif key_type == 'bcd_version': (major, minor, revision) = config_value.split('.') config_h_lines.append('') diff --git a/lib/python/qmk/cli/generate/docs.py b/lib/python/qmk/cli/generate/docs.py index 74112d834d..eb3099e138 100644 --- a/lib/python/qmk/cli/generate/docs.py +++ b/lib/python/qmk/cli/generate/docs.py @@ -10,6 +10,7 @@ DOCS_PATH = Path('docs/') BUILD_PATH = Path('.build/') BUILD_DOCS_PATH = BUILD_PATH / 'docs' DOXYGEN_PATH = BUILD_PATH / 'doxygen' +MOXYGEN_PATH = BUILD_DOCS_PATH / 'internals' @cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True) @@ -34,10 +35,10 @@ def generate_docs(cli): 'stdin': DEVNULL, } - cli.log.info('Generating internal docs...') + cli.log.info('Generating docs...') # Generate internal docs cli.run(['doxygen', 'Doxyfile'], **args) - cli.run(['moxygen', '-q', '-g', '-o', BUILD_DOCS_PATH / 'internals_%s.md', DOXYGEN_PATH / 'xml'], **args) + cli.run(['moxygen', '-q', '-g', '-o', MOXYGEN_PATH / '%s.md', DOXYGEN_PATH / 'xml'], **args) - cli.log.info('Successfully generated internal docs to %s.', BUILD_DOCS_PATH) + cli.log.info('Successfully generated docs to %s.', BUILD_DOCS_PATH) diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 29a1130f99..6f342c6567 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -21,7 +21,7 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict): return None info_key = info_dict['info_key'] - key_type = info_dict.get('value_type', 'str') + key_type = info_dict.get('value_type', 'raw') try: rules_value = kb_info_json[info_key] @@ -34,6 +34,8 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict): return f'{rules_key} ?= {"yes" if rules_value else "no"}' elif key_type == 'mapping': return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()]) + elif key_type == 'str': + return f'{rules_key} ?= "{rules_value}"' return f'{rules_key} ?= {rules_value}' diff --git a/lib/python/qmk/cli/pytest.py b/lib/python/qmk/cli/pytest.py index b7b17f0e9d..5c9c173caa 100644 --- a/lib/python/qmk/cli/pytest.py +++ b/lib/python/qmk/cli/pytest.py @@ -12,8 +12,7 @@ from milc import cli def pytest(cli): """Run several linting/testing commands. """ - nose2 = cli.run(['nose2', '-v', '-t' - 'lib/python', *cli.args.test], capture_output=False, stdin=DEVNULL) + nose2 = cli.run(['nose2', '-v', '-t', 'lib/python', *cli.args.test], capture_output=False, stdin=DEVNULL) flake8 = cli.run(['flake8', 'lib/python'], capture_output=False, stdin=DEVNULL) return flake8.returncode | nose2.returncode |