You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

655 lines
23 KiB

  1. """Functions that help us generate and use info.json files.
  2. """
  3. import json
  4. from glob import glob
  5. from pathlib import Path
  6. import jsonschema
  7. from milc import cli
  8. from qmk.constants import CHIBIOS_PROCESSORS, LUFA_PROCESSORS, VUSB_PROCESSORS, LED_INDICATORS
  9. from qmk.c_parse import find_layouts
  10. from qmk.keyboard import config_h, rules_mk
  11. from qmk.keymap import list_keymaps
  12. from qmk.makefile import parse_rules_mk_file
  13. from qmk.math import compute
  14. led_matrix_properties = {
  15. 'driver_count': 'LED_DRIVER_COUNT',
  16. 'driver_addr1': 'LED_DRIVER_ADDR_1',
  17. 'driver_addr2': 'LED_DRIVER_ADDR_2',
  18. 'driver_addr3': 'LED_DRIVER_ADDR_3',
  19. 'driver_addr4': 'LED_DRIVER_ADDR_4',
  20. 'led_count': 'LED_DRIVER_LED_COUNT',
  21. 'timeout': 'ISSI_TIMEOUT',
  22. 'persistence': 'ISSI_PERSISTENCE'
  23. }
  24. rgblight_properties = {
  25. 'led_count': 'RGBLED_NUM',
  26. 'pin': 'RGB_DI_PIN',
  27. 'split_count': 'RGBLED_SPLIT',
  28. 'max_brightness': 'RGBLIGHT_LIMIT_VAL',
  29. 'hue_steps': 'RGBLIGHT_HUE_STEP',
  30. 'saturation_steps': 'RGBLIGHT_SAT_STEP',
  31. 'brightness_steps': 'RGBLIGHT_VAL_STEP'
  32. }
  33. rgblight_toggles = {
  34. 'sleep': 'RGBLIGHT_SLEEP',
  35. 'split': 'RGBLIGHT_SPLIT',
  36. }
  37. rgblight_animations = {
  38. 'all': 'RGBLIGHT_ANIMATIONS',
  39. 'alternating': 'RGBLIGHT_EFFECT_ALTERNATING',
  40. 'breathing': 'RGBLIGHT_EFFECT_BREATHING',
  41. 'christmas': 'RGBLIGHT_EFFECT_CHRISTMAS',
  42. 'knight': 'RGBLIGHT_EFFECT_KNIGHT',
  43. 'rainbow_mood': 'RGBLIGHT_EFFECT_RAINBOW_MOOD',
  44. 'rainbow_swirl': 'RGBLIGHT_EFFECT_RAINBOW_SWIRL',
  45. 'rgb_test': 'RGBLIGHT_EFFECT_RGB_TEST',
  46. 'snake': 'RGBLIGHT_EFFECT_SNAKE',
  47. 'static_gradient': 'RGBLIGHT_EFFECT_STATIC_GRADIENT',
  48. 'twinkle': 'RGBLIGHT_EFFECT_TWINKLE'
  49. }
  50. true_values = ['1', 'on', 'yes']
  51. false_values = ['0', 'off', 'no']
  52. def info_json(keyboard):
  53. """Generate the info.json data for a specific keyboard.
  54. """
  55. cur_dir = Path('keyboards')
  56. rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')
  57. if 'DEFAULT_FOLDER' in rules:
  58. keyboard = rules['DEFAULT_FOLDER']
  59. rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk', rules)
  60. info_data = {
  61. 'keyboard_name': str(keyboard),
  62. 'keyboard_folder': str(keyboard),
  63. 'keymaps': {},
  64. 'layouts': {},
  65. 'parse_errors': [],
  66. 'parse_warnings': [],
  67. 'maintainer': 'qmk',
  68. }
  69. # Populate the list of JSON keymaps
  70. for keymap in list_keymaps(keyboard, c=False, fullpath=True):
  71. info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'}
  72. # Populate layout data
  73. for layout_name, layout_json in _find_all_layouts(info_data, keyboard).items():
  74. if not layout_name.startswith('LAYOUT_kc'):
  75. layout_json['c_macro'] = True
  76. info_data['layouts'][layout_name] = layout_json
  77. # Merge in the data from info.json, config.h, and rules.mk
  78. info_data = merge_info_jsons(keyboard, info_data)
  79. info_data = _extract_config_h(info_data)
  80. info_data = _extract_rules_mk(info_data)
  81. # Validate against the jsonschema
  82. try:
  83. keyboard_api_validate(info_data)
  84. except jsonschema.ValidationError as e:
  85. cli.log.error('Invalid info.json data: %s', e.message)
  86. print(dir(e))
  87. exit()
  88. # Make sure we have at least one layout
  89. if not info_data.get('layouts'):
  90. _log_error(info_data, 'No LAYOUTs defined! Need at least one layout defined in the keyboard.h or info.json.')
  91. # Make sure we supply layout macros for the community layouts we claim to support
  92. # FIXME(skullydazed): This should be populated into info.json and read from there instead
  93. if 'LAYOUTS' in rules and info_data.get('layouts'):
  94. # Match these up against the supplied layouts
  95. supported_layouts = rules['LAYOUTS'].strip().split()
  96. for layout_name in sorted(info_data['layouts']):
  97. layout_name = layout_name[7:]
  98. if layout_name in supported_layouts:
  99. supported_layouts.remove(layout_name)
  100. if supported_layouts:
  101. for supported_layout in supported_layouts:
  102. _log_error(info_data, 'Claims to support community layout %s but no LAYOUT_%s() macro found' % (supported_layout, supported_layout))
  103. return info_data
  104. def _json_load(json_file):
  105. """Load a json file from disk.
  106. Note: file must be a Path object.
  107. """
  108. try:
  109. return json.load(json_file.open())
  110. except json.decoder.JSONDecodeError as e:
  111. cli.log.error('Invalid JSON encountered attempting to load {fg_cyan}%s{fg_reset}:\n\t{fg_red}%s', json_file, e)
  112. exit(1)
  113. def _jsonschema(schema_name):
  114. """Read a jsonschema file from disk.
  115. """
  116. schema_path = Path(f'data/schemas/{schema_name}.jsonschema')
  117. if not schema_path.exists():
  118. schema_path = Path('data/schemas/false.jsonschema')
  119. return _json_load(schema_path)
  120. def keyboard_validate(data):
  121. """Validates data against the keyboard jsonschema.
  122. """
  123. schema = _jsonschema('keyboard')
  124. validator = jsonschema.Draft7Validator(schema).validate
  125. return validator(data)
  126. def keyboard_api_validate(data):
  127. """Validates data against the api_keyboard jsonschema.
  128. """
  129. base = _jsonschema('keyboard')
  130. relative = _jsonschema('api_keyboard')
  131. resolver = jsonschema.RefResolver.from_schema(base)
  132. validator = jsonschema.Draft7Validator(relative, resolver=resolver).validate
  133. return validator(data)
  134. def _extract_debounce(info_data, config_c):
  135. """Handle debounce.
  136. """
  137. if 'debounce' in info_data and 'DEBOUNCE' in config_c:
  138. _log_warning(info_data, 'Debounce is specified in both info.json and config.h, the config.h value wins.')
  139. if 'DEBOUNCE' in config_c:
  140. info_data['debounce'] = int(config_c['DEBOUNCE'])
  141. return info_data
  142. def _extract_diode_direction(info_data, config_c):
  143. """Handle the diode direction.
  144. """
  145. if 'diode_direction' in info_data and 'DIODE_DIRECTION' in config_c:
  146. _log_warning(info_data, 'Diode direction is specified in both info.json and config.h, the config.h value wins.')
  147. if 'DIODE_DIRECTION' in config_c:
  148. info_data['diode_direction'] = config_c.get('DIODE_DIRECTION')
  149. return info_data
  150. def _extract_indicators(info_data, config_c):
  151. """Find the LED indicator information.
  152. """
  153. for json_key, config_key in LED_INDICATORS.items():
  154. if json_key in info_data.get('indicators', []) and config_key in config_c:
  155. _log_warning(info_data, f'Indicator {json_key} is specified in both info.json and config.h, the config.h value wins.')
  156. if config_key in config_c:
  157. if 'indicators' not in info_data:
  158. info_data['indicators'] = {}
  159. info_data['indicators'][json_key] = config_c.get(config_key)
  160. return info_data
  161. def _extract_community_layouts(info_data, rules):
  162. """Find the community layouts in rules.mk.
  163. """
  164. community_layouts = rules['LAYOUTS'].split() if 'LAYOUTS' in rules else []
  165. if 'community_layouts' in info_data:
  166. for layout in community_layouts:
  167. if layout not in info_data['community_layouts']:
  168. community_layouts.append(layout)
  169. else:
  170. info_data['community_layouts'] = community_layouts
  171. return info_data
  172. def _extract_features(info_data, rules):
  173. """Find all the features enabled in rules.mk.
  174. """
  175. for key, value in rules.items():
  176. if key.endswith('_ENABLE'):
  177. key = '_'.join(key.split('_')[:-1]).lower()
  178. value = True if value in true_values else False if value in false_values else value
  179. if 'config_h_features' not in info_data:
  180. info_data['config_h_features'] = {}
  181. if 'features' not in info_data:
  182. info_data['features'] = {}
  183. if key in info_data['features']:
  184. _log_warning(info_data, 'Feature %s is specified in both info.json and rules.mk, the rules.mk value wins.' % (key,))
  185. info_data['features'][key] = value
  186. info_data['config_h_features'][key] = value
  187. return info_data
  188. def _extract_led_drivers(info_data, rules):
  189. """Find all the LED drivers set in rules.mk.
  190. """
  191. if 'LED_MATRIX_DRIVER' in rules:
  192. if 'led_matrix' not in info_data:
  193. info_data['led_matrix'] = {}
  194. if info_data['led_matrix'].get('driver'):
  195. _log_warning(info_data, 'LED Matrix driver is specified in both info.json and rules.mk, the rules.mk value wins.')
  196. info_data['led_matrix']['driver'] = rules['LED_MATRIX_DRIVER']
  197. return info_data
  198. def _extract_led_matrix(info_data, config_c):
  199. """Handle the led_matrix configuration.
  200. """
  201. led_matrix = info_data.get('led_matrix', {})
  202. for json_key, config_key in led_matrix_properties.items():
  203. if config_key in config_c:
  204. if json_key in led_matrix:
  205. _log_warning(info_data, 'LED Matrix: %s is specified in both info.json and config.h, the config.h value wins.' % (json_key,))
  206. led_matrix[json_key] = config_c[config_key]
  207. def _extract_rgblight(info_data, config_c):
  208. """Handle the rgblight configuration.
  209. """
  210. rgblight = info_data.get('rgblight', {})
  211. animations = rgblight.get('animations', {})
  212. for json_key, config_key in rgblight_properties.items():
  213. if config_key in config_c:
  214. if json_key in rgblight:
  215. _log_warning(info_data, 'RGB Light: %s is specified in both info.json and config.h, the config.h value wins.' % (json_key,))
  216. rgblight[json_key] = config_c[config_key]
  217. for json_key, config_key in rgblight_toggles.items():
  218. if config_key in config_c:
  219. if json_key in rgblight:
  220. _log_warning(info_data, 'RGB Light: %s is specified in both info.json and config.h, the config.h value wins.', json_key)
  221. rgblight[json_key] = config_c[config_key]
  222. for json_key, config_key in rgblight_animations.items():
  223. if config_key in config_c:
  224. if json_key in animations:
  225. _log_warning(info_data, 'RGB Light: animations: %s is specified in both info.json and config.h, the config.h value wins.' % (json_key,))
  226. animations[json_key] = config_c[config_key]
  227. if animations:
  228. rgblight['animations'] = animations
  229. if rgblight:
  230. info_data['rgblight'] = rgblight
  231. return info_data
  232. def _extract_matrix_info(info_data, config_c):
  233. """Populate the matrix information.
  234. """
  235. row_pins = config_c.get('MATRIX_ROW_PINS', '').replace('{', '').replace('}', '').strip()
  236. col_pins = config_c.get('MATRIX_COL_PINS', '').replace('{', '').replace('}', '').strip()
  237. direct_pins = config_c.get('DIRECT_PINS', '').replace(' ', '')[1:-1]
  238. if 'MATRIX_ROWS' in config_c and 'MATRIX_COLS' in config_c:
  239. if 'matrix_size' in info_data:
  240. _log_warning(info_data, 'Matrix size is specified in both info.json and config.h, the config.h values win.')
  241. info_data['matrix_size'] = {
  242. 'rows': compute(config_c.get('MATRIX_ROWS', '0')),
  243. 'cols': compute(config_c.get('MATRIX_COLS', '0')),
  244. }
  245. if row_pins and col_pins:
  246. if 'matrix_pins' in info_data:
  247. _log_warning(info_data, 'Matrix pins are specified in both info.json and config.h, the config.h values win.')
  248. info_data['matrix_pins'] = {}
  249. if row_pins:
  250. info_data['matrix_pins']['rows'] = row_pins.split(',')
  251. if col_pins:
  252. info_data['matrix_pins']['cols'] = col_pins.split(',')
  253. if direct_pins:
  254. if 'matrix_pins' in info_data:
  255. _log_warning(info_data, 'Direct pins are specified in both info.json and config.h, the config.h values win.')
  256. info_data['matrix_pins'] = {}
  257. direct_pin_array = []
  258. for row in direct_pins.split('},{'):
  259. if row.startswith('{'):
  260. row = row[1:]
  261. if row.endswith('}'):
  262. row = row[:-1]
  263. direct_pin_array.append([])
  264. for pin in row.split(','):
  265. if pin == 'NO_PIN':
  266. pin = None
  267. direct_pin_array[-1].append(pin)
  268. info_data['matrix_pins']['direct'] = direct_pin_array
  269. return info_data
  270. def _extract_usb_info(info_data, config_c):
  271. """Populate the USB information.
  272. """
  273. usb_properties = {'vid': 'VENDOR_ID', 'pid': 'PRODUCT_ID', 'device_ver': 'DEVICE_VER'}
  274. if 'usb' not in info_data:
  275. info_data['usb'] = {}
  276. for info_name, config_name in usb_properties.items():
  277. if config_name in config_c:
  278. if info_name in info_data['usb']:
  279. _log_warning(info_data, '%s in config.h is overwriting usb.%s in info.json' % (config_name, info_name))
  280. info_data['usb'][info_name] = config_c[config_name]
  281. elif info_name not in info_data['usb']:
  282. _log_error(info_data, '%s not specified in config.h, and %s not specified in info.json. One is required.' % (config_name, info_name))
  283. return info_data
  284. def _extract_config_h(info_data):
  285. """Pull some keyboard information from existing config.h files
  286. """
  287. config_c = config_h(info_data['keyboard_folder'])
  288. _extract_debounce(info_data, config_c)
  289. _extract_diode_direction(info_data, config_c)
  290. _extract_indicators(info_data, config_c)
  291. _extract_matrix_info(info_data, config_c)
  292. _extract_usb_info(info_data, config_c)
  293. _extract_led_matrix(info_data, config_c)
  294. _extract_rgblight(info_data, config_c)
  295. return info_data
  296. def _extract_rules_mk(info_data):
  297. """Pull some keyboard information from existing rules.mk files
  298. """
  299. rules = rules_mk(info_data['keyboard_folder'])
  300. mcu = rules.get('MCU')
  301. if mcu in CHIBIOS_PROCESSORS:
  302. arm_processor_rules(info_data, rules)
  303. elif mcu in LUFA_PROCESSORS + VUSB_PROCESSORS:
  304. avr_processor_rules(info_data, rules)
  305. else:
  306. cli.log.warning("%s: Unknown MCU: %s" % (info_data['keyboard_folder'], mcu))
  307. unknown_processor_rules(info_data, rules)
  308. _extract_community_layouts(info_data, rules)
  309. _extract_features(info_data, rules)
  310. _extract_led_drivers(info_data, rules)
  311. return info_data
  312. def _merge_layouts(info_data, new_info_data):
  313. """Merge new_info_data into info_data in an intelligent way.
  314. """
  315. for layout_name, layout_json in new_info_data['layouts'].items():
  316. if layout_name in info_data['layouts']:
  317. # Pull in layouts we have a macro for
  318. if len(info_data['layouts'][layout_name]['layout']) != len(layout_json['layout']):
  319. msg = '%s: %s: Number of elements in info.json does not match! info.json:%s != %s:%s'
  320. _log_error(info_data, msg % (info_data['keyboard_folder'], layout_name, len(layout_json['layout']), layout_name, len(info_data['layouts'][layout_name]['layout'])))
  321. else:
  322. for i, key in enumerate(info_data['layouts'][layout_name]['layout']):
  323. key.update(layout_json['layout'][i])
  324. else:
  325. # Pull in layouts that have matrix data
  326. missing_matrix = False
  327. for key in layout_json.get('layout', {}):
  328. if 'matrix' not in key:
  329. missing_matrix = True
  330. if not missing_matrix:
  331. if layout_name in info_data['layouts']:
  332. # Update an existing layout with new data
  333. for i, key in enumerate(info_data['layouts'][layout_name]['layout']):
  334. key.update(layout_json['layout'][i])
  335. else:
  336. # Copy in the new layout wholesale
  337. layout_json['c_macro'] = False
  338. info_data['layouts'][layout_name] = layout_json
  339. return info_data
  340. def _search_keyboard_h(path):
  341. current_path = Path('keyboards/')
  342. layouts = {}
  343. for directory in path.parts:
  344. current_path = current_path / directory
  345. keyboard_h = '%s.h' % (directory,)
  346. keyboard_h_path = current_path / keyboard_h
  347. if keyboard_h_path.exists():
  348. layouts.update(find_layouts(keyboard_h_path))
  349. return layouts
  350. def _find_all_layouts(info_data, keyboard):
  351. """Looks for layout macros associated with this keyboard.
  352. """
  353. layouts = _search_keyboard_h(Path(keyboard))
  354. if not layouts:
  355. # If we don't find any layouts from info.json or keyboard.h we widen our search. This is error prone which is why we want to encourage people to follow the standard above.
  356. info_data['parse_warnings'].append('%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard))
  357. for file in glob('keyboards/%s/*.h' % keyboard):
  358. if file.endswith('.h'):
  359. these_layouts = find_layouts(file)
  360. if these_layouts:
  361. layouts.update(these_layouts)
  362. return layouts
  363. def _log_error(info_data, message):
  364. """Send an error message to both JSON and the log.
  365. """
  366. info_data['parse_errors'].append(message)
  367. cli.log.error('%s: %s', info_data.get('keyboard_folder', 'Unknown Keyboard!'), message)
  368. def _log_warning(info_data, message):
  369. """Send a warning message to both JSON and the log.
  370. """
  371. info_data['parse_warnings'].append(message)
  372. cli.log.warning('%s: %s', info_data.get('keyboard_folder', 'Unknown Keyboard!'), message)
  373. def arm_processor_rules(info_data, rules):
  374. """Setup the default info for an ARM board.
  375. """
  376. info_data['processor_type'] = 'arm'
  377. info_data['protocol'] = 'ChibiOS'
  378. if 'MCU' in rules:
  379. if 'processor' in info_data:
  380. _log_warning(info_data, 'Processor/MCU is specified in both info.json and rules.mk, the rules.mk value wins.')
  381. info_data['processor'] = rules['MCU']
  382. elif 'processor' not in info_data:
  383. info_data['processor'] = 'unknown'
  384. if 'BOOTLOADER' in rules:
  385. if 'bootloader' in info_data:
  386. _log_warning(info_data, 'Bootloader is specified in both info.json and rules.mk, the rules.mk value wins.')
  387. info_data['bootloader'] = rules['BOOTLOADER']
  388. else:
  389. if 'STM32' in info_data['processor']:
  390. info_data['bootloader'] = 'stm32-dfu'
  391. else:
  392. info_data['bootloader'] = 'unknown'
  393. if 'STM32' in info_data['processor']:
  394. info_data['platform'] = 'STM32'
  395. elif 'MCU_SERIES' in rules:
  396. info_data['platform'] = rules['MCU_SERIES']
  397. elif 'ARM_ATSAM' in rules:
  398. info_data['platform'] = 'ARM_ATSAM'
  399. return info_data
  400. def avr_processor_rules(info_data, rules):
  401. """Setup the default info for an AVR board.
  402. """
  403. info_data['processor_type'] = 'avr'
  404. info_data['bootloader'] = rules['BOOTLOADER'] if 'BOOTLOADER' in rules else 'atmel-dfu'
  405. info_data['platform'] = rules['ARCH'] if 'ARCH' in rules else 'unknown'
  406. info_data['protocol'] = 'V-USB' if rules.get('MCU') in VUSB_PROCESSORS else 'LUFA'
  407. if 'MCU' in rules:
  408. if 'processor' in info_data:
  409. _log_warning(info_data, 'Processor/MCU is specified in both info.json and rules.mk, the rules.mk value wins.')
  410. info_data['processor'] = rules['MCU']
  411. elif 'processor' not in info_data:
  412. info_data['processor'] = 'unknown'
  413. if 'BOOTLOADER' in rules:
  414. if 'bootloader' in info_data:
  415. _log_warning(info_data, 'Bootloader is specified in both info.json and rules.mk, the rules.mk value wins.')
  416. info_data['bootloader'] = rules['BOOTLOADER']
  417. else:
  418. info_data['bootloader'] = 'atmel-dfu'
  419. # FIXME(fauxpark/anyone): Eventually we should detect the protocol by looking at PROTOCOL inherited from mcu_selection.mk:
  420. # info_data['protocol'] = 'V-USB' if rules.get('PROTOCOL') == 'VUSB' else 'LUFA'
  421. return info_data
  422. def unknown_processor_rules(info_data, rules):
  423. """Setup the default keyboard info for unknown boards.
  424. """
  425. info_data['bootloader'] = 'unknown'
  426. info_data['platform'] = 'unknown'
  427. info_data['processor'] = 'unknown'
  428. info_data['processor_type'] = 'unknown'
  429. info_data['protocol'] = 'unknown'
  430. return info_data
  431. def merge_info_jsons(keyboard, info_data):
  432. """Return a merged copy of all the info.json files for a keyboard.
  433. """
  434. for info_file in find_info_json(keyboard):
  435. # Load and validate the JSON data
  436. try:
  437. new_info_data = _json_load(info_file)
  438. keyboard_validate(new_info_data)
  439. except jsonschema.ValidationError as e:
  440. cli.log.error('Invalid info.json data: %s', e.message)
  441. cli.log.error('Not including file %s', info_file)
  442. continue
  443. if not isinstance(new_info_data, dict):
  444. _log_error(info_data, "Invalid file %s, root object should be a dictionary." % (str(info_file),))
  445. continue
  446. # Copy whitelisted keys into `info_data`
  447. for key in ('debounce', 'diode_direction', 'indicators', 'keyboard_name', 'manufacturer', 'identifier', 'url', 'maintainer', 'processor', 'bootloader', 'width', 'height'):
  448. if key in new_info_data:
  449. info_data[key] = new_info_data[key]
  450. # Deep merge certain keys
  451. # FIXME(skullydazed/anyone): this should be generalized more so that we can inteligently merge more than one level deep. It would be nice if we could filter on valid keys too. That may have to wait for a future where we use openapi or something.
  452. for key in ('features', 'layout_aliases', 'led_matrix', 'matrix_pins', 'rgblight', 'usb'):
  453. if key in new_info_data:
  454. if key not in info_data:
  455. info_data[key] = {}
  456. info_data[key].update(new_info_data[key])
  457. # Merge the layouts
  458. if 'community_layouts' in new_info_data:
  459. if 'community_layouts' in info_data:
  460. for layout in new_info_data['community_layouts']:
  461. if layout not in info_data['community_layouts']:
  462. info_data['community_layouts'].append(layout)
  463. else:
  464. info_data['community_layouts'] = new_info_data['community_layouts']
  465. if 'layouts' in new_info_data:
  466. _merge_layouts(info_data, new_info_data)
  467. return info_data
  468. def find_info_json(keyboard):
  469. """Finds all the info.json files associated with a keyboard.
  470. """
  471. # Find the most specific first
  472. base_path = Path('keyboards')
  473. keyboard_path = base_path / keyboard
  474. keyboard_parent = keyboard_path.parent
  475. info_jsons = [keyboard_path / 'info.json']
  476. # Add DEFAULT_FOLDER before parents, if present
  477. rules = rules_mk(keyboard)
  478. if 'DEFAULT_FOLDER' in rules:
  479. info_jsons.append(Path(rules['DEFAULT_FOLDER']) / 'info.json')
  480. # Add in parent folders for least specific
  481. for _ in range(5):
  482. info_jsons.append(keyboard_parent / 'info.json')
  483. if keyboard_parent.parent == base_path:
  484. break
  485. keyboard_parent = keyboard_parent.parent
  486. # Return a list of the info.json files that actually exist
  487. return [info_json for info_json in info_jsons if info_json.exists()]