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

Reduce _validate complexity #20274

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Changes from all commits
Commits
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
28 changes: 17 additions & 11 deletions lib/python/qmk/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,9 @@ def _valid_community_layout(layout):
return (Path('layouts/default') / layout).exists()


def _validate(keyboard, info_data):
"""Perform various validation on the provided info.json data
def _additional_validation(keyboard, info_data):
"""Non schema checks
"""
# First validate against the jsonschema
try:
validate(info_data, 'qmk.api.keyboard.v1')

except jsonschema.ValidationError as e:
json_path = '.'.join([str(p) for p in e.absolute_path])
cli.log.error('Invalid API data: %s: %s: %s', keyboard, json_path, e.message)
exit(1)

layouts = info_data.get('layouts', {})
layout_aliases = info_data.get('layout_aliases', {})
community_layouts = info_data.get('community_layouts', [])
Expand Down Expand Up @@ -110,6 +101,21 @@ def _validate(keyboard, info_data):
_log_error(info_data, f'Keycode {decl["key"]} has no short form alias')


def _validate(keyboard, info_data):
"""Perform various validation on the provided info.json data
"""
# First validate against the jsonschema
try:
validate(info_data, 'qmk.api.keyboard.v1')

_additional_validation(keyboard, info_data)

except jsonschema.ValidationError as e:
json_path = '.'.join([str(p) for p in e.absolute_path])
cli.log.error('Invalid API data: %s: %s: %s', keyboard, json_path, e.message)
exit(1)


def info_json(keyboard):
"""Generate the info.json data for a specific keyboard.
"""
Expand Down