Skip to content

Commit

Permalink
Reduce _validate complexity (qmk#20274)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored and nicsuzor committed Mar 28, 2023
1 parent 9eb6c9f commit fe08cd5
Showing 1 changed file with 17 additions and 11 deletions.
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

0 comments on commit fe08cd5

Please sign in to comment.