summaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2022-06-09 21:02:16 +0100
committerGitHub <noreply@github.com>2022-06-09 21:02:16 +0100
commita599550adbd6b1291509d7cdc7ea61c92550a60c (patch)
treeb878a1da9541a4e4fd25c4861f0fd340b646b9c2 /lib/python
parentde43b09d25e83d97cb8e26177f28d1f391ff9c4f (diff)
Add support for linting deprecated and removed functionality (#17063)
* Add support for more lint warnings/errors * Develop currently needs extra deps installed * Lint a few more scenarios * fix tests
Diffstat (limited to 'lib/python')
-rw-r--r--lib/python/qmk/info.py120
-rw-r--r--lib/python/qmk/tests/test_cli_commands.py1
2 files changed, 53 insertions, 68 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index 0763433b3d..6ff9cba45b 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -440,6 +440,47 @@ def _extract_device_version(info_data):
440 info_data['usb']['device_version'] = f'{major}.{minor}.{revision}' 440 info_data['usb']['device_version'] = f'{major}.{minor}.{revision}'
441 441
442 442
443def _config_to_json(key_type, config_value):
444 """Convert config value using spec
445 """
446 if key_type.startswith('array'):
447 if '.' in key_type:
448 key_type, array_type = key_type.split('.', 1)
449 else:
450 array_type = None
451
452 config_value = config_value.replace('{', '').replace('}', '').strip()
453
454 if array_type == 'int':
455 return list(map(int, config_value.split(',')))
456 else:
457 return config_value.split(',')
458
459 elif key_type == 'bool':
460 return config_value in true_values
461
462 elif key_type == 'hex':
463 return '0x' + config_value[2:].upper()
464
465 elif key_type == 'list':
466 return config_value.split()
467
468 elif key_type == 'int':
469 return int(config_value)
470
471 elif key_type == 'str':
472 return config_value.strip('"')
473
474 elif key_type == 'bcd_version':
475 major = int(config_value[2:4])
476 minor = int(config_value[4])
477 revision = int(config_value[5])
478
479 return f'{major}.{minor}.{revision}'
480
481 return config_value
482
483
443def _extract_config_h(info_data, config_c): 484def _extract_config_h(info_data, config_c):
444 """Pull some keyboard information from existing config.h files 485 """Pull some keyboard information from existing config.h files
445 """ 486 """
@@ -452,47 +493,16 @@ def _extract_config_h(info_data, config_c):
452 key_type = info_dict.get('value_type', 'raw') 493 key_type = info_dict.get('value_type', 'raw')
453 494
454 try: 495 try:
496 if config_key in config_c and info_dict.get('invalid', False):
497 _log_error(info_data, '%s in config.h is no longer a valid option' % config_key)
498 elif config_key in config_c and info_dict.get('deprecated', False):
499 _log_warning(info_data, '%s in config.h is deprecated and will be removed at a later date' % config_key)
500
455 if config_key in config_c and info_dict.get('to_json', True): 501 if config_key in config_c and info_dict.get('to_json', True):
456 if dotty_info.get(info_key) and info_dict.get('warn_duplicate', True): 502 if dotty_info.get(info_key) and info_dict.get('warn_duplicate', True):
457 _log_warning(info_data, '%s in config.h is overwriting %s in info.json' % (config_key, info_key)) 503 _log_warning(info_data, '%s in config.h is overwriting %s in info.json' % (config_key, info_key))
458 504
459 if key_type.startswith('array'): 505 dotty_info[info_key] = _config_to_json(key_type, config_c[config_key])
460 if '.' in key_type:
461 key_type, array_type = key_type.split('.', 1)
462 else:
463 array_type = None
464
465 config_value = config_c[config_key].replace('{', '').replace('}', '').strip()
466
467 if array_type == 'int':
468 dotty_info[info_key] = list(map(int, config_value.split(',')))
469 else:
470 dotty_info[info_key] = config_value.split(',')
471
472 elif key_type == 'bool':
473 dotty_info[info_key] = config_c[config_key] in true_values
474
475 elif key_type == 'hex':
476 dotty_info[info_key] = '0x' + config_c[config_key][2:].upper()
477
478 elif key_type == 'list':
479 dotty_info[info_key] = config_c[config_key].split()
480
481 elif key_type == 'int':
482 dotty_info[info_key] = int(config_c[config_key])
483
484 elif key_type == 'str':
485 dotty_info[info_key] = config_c[config_key].strip('"')
486
487 elif key_type == 'bcd_version':
488 major = int(config_c[config_key][2:4])
489 minor = int(config_c[config_key][4])
490 revision = int(config_c[config_key][5])
491
492 dotty_info[info_key] = f'{major}.{minor}.{revision}'
493
494 else:
495 dotty_info[info_key] = config_c[config_key]
496 506
497 except Exception as e: 507 except Exception as e:
498 _log_warning(info_data, f'{config_key}->{info_key}: {e}') 508 _log_warning(info_data, f'{config_key}->{info_key}: {e}')
@@ -547,40 +557,16 @@ def _extract_rules_mk(info_data, rules):
547 key_type = info_dict.get('value_type', 'raw') 557 key_type = info_dict.get('value_type', 'raw')
548 558
549 try: 559 try:
560 if rules_key in rules and info_dict.get('invalid', False):
561 _log_error(info_data, '%s in rules.mk is no longer a valid option' % rules_key)
562 elif rules_key in rules and info_dict.get('deprecated', False):
563 _log_warning(info_data, '%s in rules.mk is deprecated and will be removed at a later date' % rules_key)
564
550 if rules_key in rules and info_dict.get('to_json', True): 565 if rules_key in rules and info_dict.get('to_json', True):
551 if dotty_info.get(info_key) and info_dict.get('warn_duplicate', True): 566 if dotty_info.get(info_key) and info_dict.get('warn_duplicate', True):
552 _log_warning(info_data, '%s in rules.mk is overwriting %s in info.json' % (rules_key, info_key)) 567 _log_warning(info_data, '%s in rules.mk is overwriting %s in info.json' % (rules_key, info_key))
553 568
554 if key_type.startswith('array'): 569 dotty_info[info_key] = _config_to_json(key_type, rules[rules_key])
555 if '.' in key_type:
556 key_type, array_type = key_type.split('.', 1)
557 else:
558 array_type = None
559
560 rules_value = rules[rules_key].replace('{', '').replace('}', '').strip()
561
562 if array_type == 'int':
563 dotty_info[info_key] = list(map(int, rules_value.split(',')))
564 else:
565 dotty_info[info_key] = rules_value.split(',')
566
567 elif key_type == 'list':
568 dotty_info[info_key] = rules[rules_key].split()
569
570 elif key_type == 'bool':
571 dotty_info[info_key] = rules[rules_key] in true_values
572
573 elif key_type == 'hex':
574 dotty_info[info_key] = '0x' + rules[rules_key][2:].upper()
575
576 elif key_type == 'int':
577 dotty_info[info_key] = int(rules[rules_key])
578
579 elif key_type == 'str':
580 dotty_info[info_key] = rules[rules_key].strip('"')
581
582 else:
583 dotty_info[info_key] = rules[rules_key]
584 570
585 except Exception as e: 571 except Exception as e:
586 _log_warning(info_data, f'{rules_key}->{info_key}: {e}') 572 _log_warning(info_data, f'{rules_key}->{info_key}: {e}')
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
index d40d4bf573..2463543ef1 100644
--- a/lib/python/qmk/tests/test_cli_commands.py
+++ b/lib/python/qmk/tests/test_cli_commands.py
@@ -259,7 +259,6 @@ def test_generate_config_h():
259 result = check_subcommand('generate-config-h', '-kb', 'handwired/pytest/basic') 259 result = check_subcommand('generate-config-h', '-kb', 'handwired/pytest/basic')
260 check_returncode(result) 260 check_returncode(result)
261 assert '# define DEVICE_VER 0x0001' in result.stdout 261 assert '# define DEVICE_VER 0x0001' in result.stdout
262 assert '# define DESCRIPTION "handwired/pytest/basic"' in result.stdout
263 assert '# define DIODE_DIRECTION COL2ROW' in result.stdout 262 assert '# define DIODE_DIRECTION COL2ROW' in result.stdout
264 assert '# define MANUFACTURER none' in result.stdout 263 assert '# define MANUFACTURER none' in result.stdout
265 assert '# define PRODUCT pytest' in result.stdout 264 assert '# define PRODUCT pytest' in result.stdout