diff options
author | Joel Challis <git@zvecr.com> | 2022-06-09 21:02:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 21:02:16 +0100 |
commit | a599550adbd6b1291509d7cdc7ea61c92550a60c (patch) | |
tree | b878a1da9541a4e4fd25c4861f0fd340b646b9c2 /lib | |
parent | de43b09d25e83d97cb8e26177f28d1f391ff9c4f (diff) | |
download | qmk_firmware-a599550adbd6b1291509d7cdc7ea61c92550a60c.tar.gz qmk_firmware-a599550adbd6b1291509d7cdc7ea61c92550a60c.zip |
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')
-rw-r--r-- | lib/python/qmk/info.py | 120 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 1 |
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): info_data['usb']['device_version'] = f'{major}.{minor}.{revision}' +def _config_to_json(key_type, config_value): + """Convert config value using spec + """ + if key_type.startswith('array'): + if '.' in key_type: + key_type, array_type = key_type.split('.', 1) + else: + array_type = None + + config_value = config_value.replace('{', '').replace('}', '').strip() + + if array_type == 'int': + return list(map(int, config_value.split(','))) + else: + return config_value.split(',') + + elif key_type == 'bool': + return config_value in true_values + + elif key_type == 'hex': + return '0x' + config_value[2:].upper() + + elif key_type == 'list': + return config_value.split() + + elif key_type == 'int': + return int(config_value) + + elif key_type == 'str': + return config_value.strip('"') + + elif key_type == 'bcd_version': + major = int(config_value[2:4]) + minor = int(config_value[4]) + revision = int(config_value[5]) + + return f'{major}.{minor}.{revision}' + + return config_value + + def _extract_config_h(info_data, config_c): """Pull some keyboard information from existing config.h files """ @@ -452,47 +493,16 @@ def _extract_config_h(info_data, config_c): key_type = info_dict.get('value_type', 'raw') try: + if config_key in config_c and info_dict.get('invalid', False): + _log_error(info_data, '%s in config.h is no longer a valid option' % config_key) + elif config_key in config_c and info_dict.get('deprecated', False): + _log_warning(info_data, '%s in config.h is deprecated and will be removed at a later date' % config_key) + if config_key in config_c and info_dict.get('to_json', True): if dotty_info.get(info_key) and info_dict.get('warn_duplicate', True): _log_warning(info_data, '%s in config.h is overwriting %s in info.json' % (config_key, info_key)) - if key_type.startswith('array'): - if '.' in key_type: - key_type, array_type = key_type.split('.', 1) - else: - array_type = None - - config_value = config_c[config_key].replace('{', '').replace('}', '').strip() - - if array_type == 'int': - dotty_info[info_key] = list(map(int, config_value.split(','))) - else: - dotty_info[info_key] = config_value.split(',') - - elif key_type == 'bool': - dotty_info[info_key] = config_c[config_key] in true_values - - elif key_type == 'hex': - dotty_info[info_key] = '0x' + config_c[config_key][2:].upper() - - elif key_type == 'list': - dotty_info[info_key] = config_c[config_key].split() - - elif key_type == 'int': - dotty_info[info_key] = int(config_c[config_key]) - - elif key_type == 'str': - dotty_info[info_key] = config_c[config_key].strip('"') - - elif key_type == 'bcd_version': - major = int(config_c[config_key][2:4]) - minor = int(config_c[config_key][4]) - revision = int(config_c[config_key][5]) - - dotty_info[info_key] = f'{major}.{minor}.{revision}' - - else: - dotty_info[info_key] = config_c[config_key] + dotty_info[info_key] = _config_to_json(key_type, config_c[config_key]) except Exception as e: _log_warning(info_data, f'{config_key}->{info_key}: {e}') @@ -547,40 +557,16 @@ def _extract_rules_mk(info_data, rules): key_type = info_dict.get('value_type', 'raw') try: + if rules_key in rules and info_dict.get('invalid', False): + _log_error(info_data, '%s in rules.mk is no longer a valid option' % rules_key) + elif rules_key in rules and info_dict.get('deprecated', False): + _log_warning(info_data, '%s in rules.mk is deprecated and will be removed at a later date' % rules_key) + if rules_key in rules and info_dict.get('to_json', True): if dotty_info.get(info_key) and info_dict.get('warn_duplicate', True): _log_warning(info_data, '%s in rules.mk is overwriting %s in info.json' % (rules_key, info_key)) - if key_type.startswith('array'): - if '.' in key_type: - key_type, array_type = key_type.split('.', 1) - else: - array_type = None - - rules_value = rules[rules_key].replace('{', '').replace('}', '').strip() - - if array_type == 'int': - dotty_info[info_key] = list(map(int, rules_value.split(','))) - else: - dotty_info[info_key] = rules_value.split(',') - - elif key_type == 'list': - dotty_info[info_key] = rules[rules_key].split() - - elif key_type == 'bool': - dotty_info[info_key] = rules[rules_key] in true_values - - elif key_type == 'hex': - dotty_info[info_key] = '0x' + rules[rules_key][2:].upper() - - elif key_type == 'int': - dotty_info[info_key] = int(rules[rules_key]) - - elif key_type == 'str': - dotty_info[info_key] = rules[rules_key].strip('"') - - else: - dotty_info[info_key] = rules[rules_key] + dotty_info[info_key] = _config_to_json(key_type, rules[rules_key]) except Exception as e: _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(): result = check_subcommand('generate-config-h', '-kb', 'handwired/pytest/basic') check_returncode(result) assert '# define DEVICE_VER 0x0001' in result.stdout - assert '# define DESCRIPTION "handwired/pytest/basic"' in result.stdout assert '# define DIODE_DIRECTION COL2ROW' in result.stdout assert '# define MANUFACTURER none' in result.stdout assert '# define PRODUCT pytest' in result.stdout |