Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lot more data to info.json #13366

Merged
merged 37 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c15431b
add some split data to info.json
skullydazed Jun 25, 2021
06bbd07
add tags
skullydazed Jun 25, 2021
e6ae983
add half of config_options.md to info.json
skullydazed Jun 25, 2021
021fa69
add support for designating master split
skullydazed Jun 25, 2021
d6e152b
sort out split transport and primary
skullydazed Jun 26, 2021
cd1c3fc
fix bad data in UNUSED_PINS
skullydazed Jun 26, 2021
c09216e
fixup custom transport
skullydazed Jun 26, 2021
aa29277
wip
skullydazed Jun 26, 2021
dad8f59
allow for setting split right half keyboard matrix
skullydazed Jun 28, 2021
8d4494c
add SPLIT_USB_DETECT
skullydazed Jun 28, 2021
191f78f
minor cleanup
skullydazed Jun 28, 2021
c0f3ceb
fix an erroneous message
skullydazed Jun 28, 2021
5356204
rework split.usb_detect
skullydazed Jun 28, 2021
0fe118e
adding missing rgblight vars to info.json
skullydazed Jun 28, 2021
605e23a
add mouse_key to info.json
skullydazed Jun 28, 2021
a969a80
add all remaining options from docs/config_options.md
skullydazed Jun 28, 2021
e7a5922
fix audio voices
skullydazed Jun 28, 2021
3f6e62b
qmk info: Change text output to use dotted notation
skullydazed Jun 26, 2021
9cca69d
tweak layout output
skullydazed Jun 28, 2021
0845e3f
resolve alias names
skullydazed Jun 28, 2021
089c94f
break out some functions to make flake8 happy
skullydazed Jul 11, 2021
173117d
add a field for bootloader instructions
skullydazed Jul 11, 2021
6eb427e
qmk generate-info-json: add a write-to-file argument
noroadsleft Jun 28, 2021
1241228
-arg_only, +action
noroadsleft Jun 28, 2021
40dfded
Bring qmk generate-info-json inline with other generate commands
skullydazed Jul 23, 2021
c00b002
pytest fixup
skullydazed Jul 23, 2021
87a4fde
fix esca/getawayvan
skullydazed Aug 9, 2021
6b4293f
fix data driven errors for bpiphany converters
skullydazed Aug 9, 2021
9f13125
features.force_nkro -> usb.force_nkro
skullydazed Aug 9, 2021
26c3ab3
split.primary->split.main
skullydazed Aug 9, 2021
3389e50
fix esca/getawayvan_f042
skullydazed Aug 9, 2021
3be4330
fix the bpiphany converters for real
skullydazed Aug 9, 2021
967a21d
fix bpiphany/tiger_lily
skullydazed Aug 10, 2021
ae29ea4
Apply suggestions from code review
skullydazed Aug 16, 2021
b885c63
fix generate-api errors
skullydazed Aug 16, 2021
0ca7238
fix matrix pin extraction for split boards
skullydazed Aug 16, 2021
7a5f286
fix ploopyco/trackball_nano/rev1_001
skullydazed Aug 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bring qmk generate-info-json inline with other generate commands
  • Loading branch information
skullydazed committed Aug 16, 2021
commit 40dfdedb8893b86fc893cb2ac8249de6441d5f90
46 changes: 31 additions & 15 deletions lib/python/qmk/cli/generate/info_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
"""
import json

from jsonschema import Draft7Validator, validators
from argcomplete.completers import FilesCompleter
from jsonschema import Draft7Validator, RefResolver, validators
from milc import cli
from pathlib import Path

from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.info import info_json
from qmk.json_encoders import InfoJSONEncoder
from qmk.json_schema import load_jsonschema
from qmk.json_schema import compile_schema_store, load_jsonschema
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.path import is_keyboard
from qmk.path import is_keyboard, normpath


def pruning_validator(validator_class):
Expand All @@ -35,16 +36,19 @@ def remove_additional_properties(validator, properties, instance, schema):
def strip_info_json(kb_info_json):
"""Remove the API-only properties from the info.json.
"""
schema_store = compile_schema_store()
pruning_draft_7_validator = pruning_validator(Draft7Validator)
schema = load_jsonschema('qmk.keyboard.v1')
validator = pruning_draft_7_validator(schema).validate
schema = schema_store['qmk.keyboard.v1']
resolver = RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store)
validator = pruning_draft_7_validator(schema, resolver=resolver).validate

return validator(kb_info_json)


@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to show info for.')
@cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.')
@cli.argument('-o', '--output', action='store_true', help='Write the output to a file.')
@cli.argument('-o', '--output', arg_only=True, completer=FilesCompleter, help='Write the output the specified file, overwriting if necessary.')
@cli.argument('-ow', '--overwrite', arg_only=True, action='store_true', help='Overwrite the existing info.json. (Overrides the location of --output)')
@cli.subcommand('Generate an info.json file for a keyboard.', hidden=False if cli.config.user.developer else True)
@automagic_keyboard
@automagic_keymap
Expand All @@ -61,17 +65,29 @@ def generate_info_json(cli):
cli.log.error('Invalid keyboard: "%s"', cli.config.generate_info_json.keyboard)
return False

if cli.args.overwrite:
output_path = (Path('keyboards') / cli.config.generate_info_json.keyboard / 'info.json').resolve()

if cli.args.output:
cli.log.warning('Overwriting user supplied --output with %s', output_path)

cli.args.output = output_path

# Build the info.json file
kb_info_json = info_json(cli.config.generate_info_json.keyboard)
strip_info_json(kb_info_json)
info_json_text = json.dumps(kb_info_json, indent=4, cls=InfoJSONEncoder)

# Display the results
print(json.dumps(kb_info_json, indent=2, cls=InfoJSONEncoder))

# Write to a file if --output flag was specified
if cli.args.output:
output_path = Path('keyboards') / cli.config.generate_info_json.keyboard / 'info.json'
with open(output_path, 'w+') as json_file:
json_object = json.dumps(kb_info_json, indent=4, cls=InfoJSONEncoder)
json_file.write(json_object)
cli.log.info('Wrote file to %s.', output_path)
# Write to a file
output_path = normpath(cli.args.output)

if output_path.exists():
cli.log.warning('Overwriting output file %s', output_path)

output_path.write_text(info_json_text + '\n')
cli.log.info('Wrote info.json to %s.', output_path)

else:
# Display the results
print(info_json_text)
12 changes: 10 additions & 2 deletions lib/python/qmk/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def load_jsonschema(schema_name):


@lru_cache(maxsize=0)
def create_validator(schema):
"""Creates a validator for the given schema id.
def compile_schema_store():
"""Compile all our schemas into a schema store.
"""
schema_store = {}

Expand All @@ -54,6 +54,14 @@ def create_validator(schema):
continue
schema_store[schema_data['$id']] = schema_data

return schema_store


@lru_cache(maxsize=0)
def create_validator(schema):
"""Creates a validator for the given schema id.
"""
schema_store = compile_schema_store()
resolver = jsonschema.RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store)

return jsonschema.Draft7Validator(schema_store[schema], resolver=resolver).validate
Expand Down