diff options
| author | Joel Challis <git@zvecr.com> | 2022-11-23 18:01:07 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-23 18:01:07 +0000 |
| commit | dfa53900dcc7e67db70c9ef7bdb14e4a423349f9 (patch) | |
| tree | 897c8fde0c706e55165c64c6a041a5040d23a021 /lib/python/qmk/cli/generate/api.py | |
| parent | bebfdad795add9fbc8c6c1393d1b817d542474ed (diff) | |
Publish constants metadata to API (#19143)
* Publish metadata
* Ensure content is sorted
Diffstat (limited to 'lib/python/qmk/cli/generate/api.py')
| -rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index a98a12b628..8650a36b84 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py | |||
| @@ -18,6 +18,23 @@ TEMPLATE_PATH = DATA_PATH / 'templates/api/' | |||
| 18 | BUILD_API_PATH = Path('.build/api_data/') | 18 | BUILD_API_PATH = Path('.build/api_data/') |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | def _list_constants(output_folder): | ||
| 22 | """Produce a map of available constants | ||
| 23 | """ | ||
| 24 | ret = {} | ||
| 25 | for file in (output_folder / 'constants').glob('**/*_[0-9].[0-9].[0-9].json'): | ||
| 26 | name, version = file.stem.rsplit('_', 1) | ||
| 27 | if name not in ret: | ||
| 28 | ret[name] = [] | ||
| 29 | ret[name].append(version) | ||
| 30 | |||
| 31 | # Ensure content is sorted | ||
| 32 | for name in ret: | ||
| 33 | ret[name] = sorted(ret[name]) | ||
| 34 | |||
| 35 | return ret | ||
| 36 | |||
| 37 | |||
| 21 | def _resolve_keycode_specs(output_folder): | 38 | def _resolve_keycode_specs(output_folder): |
| 22 | """To make it easier for consumers, publish pre-merged spec files | 39 | """To make it easier for consumers, publish pre-merged spec files |
| 23 | """ | 40 | """ |
| @@ -69,6 +86,7 @@ def generate_api(cli): | |||
| 69 | keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets | 86 | keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets |
| 70 | keyboard_aliases_file = v1_dir / 'keyboard_aliases.json' # A list of historical keyboard names and their new name | 87 | keyboard_aliases_file = v1_dir / 'keyboard_aliases.json' # A list of historical keyboard names and their new name |
| 71 | keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization | 88 | keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization |
| 89 | constants_metadata_file = v1_dir / 'constants_metadata.json' # Metadata for available constants | ||
| 72 | usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target | 90 | usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target |
| 73 | 91 | ||
| 74 | if BUILD_API_PATH.exists(): | 92 | if BUILD_API_PATH.exists(): |
| @@ -132,6 +150,7 @@ def generate_api(cli): | |||
| 132 | keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, cls=InfoJSONEncoder) | 150 | keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, cls=InfoJSONEncoder) |
| 133 | keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, cls=InfoJSONEncoder) | 151 | keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, cls=InfoJSONEncoder) |
| 134 | keyboard_metadata_json = json.dumps(keyboard_metadata, cls=InfoJSONEncoder) | 152 | keyboard_metadata_json = json.dumps(keyboard_metadata, cls=InfoJSONEncoder) |
| 153 | constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}) | ||
| 135 | 154 | ||
| 136 | if not cli.args.dry_run: | 155 | if not cli.args.dry_run: |
| 137 | keyboard_all_file.write_text(keyboard_all_json) | 156 | keyboard_all_file.write_text(keyboard_all_json) |
| @@ -139,3 +158,4 @@ def generate_api(cli): | |||
| 139 | keyboard_list_file.write_text(keyboard_list_json) | 158 | keyboard_list_file.write_text(keyboard_list_json) |
| 140 | keyboard_aliases_file.write_text(keyboard_aliases_json) | 159 | keyboard_aliases_file.write_text(keyboard_aliases_json) |
| 141 | keyboard_metadata_file.write_text(keyboard_metadata_json) | 160 | keyboard_metadata_file.write_text(keyboard_metadata_json) |
| 161 | constants_metadata_file.write_text(constants_metadata_json) | ||
