diff options
author | Drashna Jael're <drashna@live.com> | 2022-01-21 11:18:09 -0800 |
---|---|---|
committer | Drashna Jael're <drashna@live.com> | 2022-01-21 11:18:09 -0800 |
commit | 0ebd0de6f62c50e74a72ad5260fe1b8b5f2d3758 (patch) | |
tree | fd71523aa21d1c0930ccdeac2886abbd36407cd1 /lib/python/qmk | |
parent | 00d0bd6c610303f42a855ae4d4c7f90dab40c39d (diff) |
Fix qmk cli isues'
Diffstat (limited to 'lib/python/qmk')
-rw-r--r-- | lib/python/qmk/cli/config.py | 116 | ||||
-rw-r--r-- | lib/python/qmk/cli/doctor/linux.py | 11 | ||||
-rw-r--r-- | lib/python/qmk/cli/format/c.py | 29 | ||||
-rwxr-xr-x | lib/python/qmk/cli/format/python.py | 3 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/compilation_database.py | 3 | ||||
-rw-r--r-- | lib/python/qmk/cli/json/__init__.py | 5 | ||||
-rwxr-xr-x | lib/python/qmk/cli/json/keymap.py | 16 | ||||
-rw-r--r-- | lib/python/qmk/cli/pytest.py | 3 | ||||
-rw-r--r-- | lib/python/qmk/constants.py | 2 | ||||
-rw-r--r-- | lib/python/qmk/path.py | 1 | ||||
-rw-r--r-- | lib/python/qmk/tests/onekey_export.json | 6 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 16 |
12 files changed, 31 insertions, 180 deletions
diff --git a/lib/python/qmk/cli/config.py b/lib/python/qmk/cli/config.py deleted file mode 100644 index e17d8bb9ba..0000000000 --- a/lib/python/qmk/cli/config.py +++ /dev/null @@ -1,116 +0,0 @@ -"""Read and write configuration settings -""" -from milc import cli - - -def print_config(section, key): - """Print a single config setting to stdout. - """ - cli.echo('%s.%s{fg_cyan}={fg_reset}%s', section, key, cli.config[section][key]) - - -def show_config(): - """Print the current configuration to stdout. - """ - for section in cli.config: - for key in cli.config[section]: - print_config(section, key) - - -def parse_config_token(config_token): - """Split a user-supplied configuration-token into its components. - """ - section = option = value = None - - if '=' in config_token and '.' not in config_token: - cli.log.error('Invalid configuration token, the key must be of the form <section>.<option>: %s', config_token) - return section, option, value - - # Separate the key (<section>.<option>) from the value - if '=' in config_token: - key, value = config_token.split('=') - else: - key = config_token - - # Extract the section and option from the key - if '.' in key: - section, option = key.split('.', 1) - else: - section = key - - return section, option, value - - -def set_config(section, option, value): - """Set a config key in the running config. - """ - log_string = '%s.%s{fg_cyan}:{fg_reset} %s {fg_cyan}->{fg_reset} %s' - if cli.args.read_only: - log_string += ' {fg_red}(change not written)' - - cli.echo(log_string, section, option, cli.config[section][option], value) - - if not cli.args.read_only: - if value == 'None': - del cli.config[section][option] - else: - cli.config[section][option] = value - - -@cli.argument('-ro', '--read-only', arg_only=True, action='store_true', help='Operate in read-only mode.') -@cli.argument('configs', nargs='*', arg_only=True, help='Configuration options to read or write.') -@cli.subcommand("Read and write configuration settings.") -def config(cli): - """Read and write config settings. - - This script iterates over the config_tokens supplied as argument. Each config_token has the following form: - - section[.key][=value] - - If only a section (EG 'compile') is supplied all keys for that section will be displayed. - - If section.key is supplied the value for that single key will be displayed. - - If section.key=value is supplied the value for that single key will be set. - - If section.key=None is supplied the key will be deleted. - - No validation is done to ensure that the supplied section.key is actually used by qmk scripts. - """ - if not cli.args.configs: - return show_config() - - # Process config_tokens - save_config = False - - for argument in cli.args.configs: - # Split on space in case they quoted multiple config tokens - for config_token in argument.split(' '): - section, option, value = parse_config_token(config_token) - - # Validation - if option and '.' in option: - cli.log.error('Config keys may not have more than one period! "%s" is not valid.', config_token) - return False - - # Do what the user wants - if section and option and value: - # Write a configuration option - set_config(section, option, value) - if not cli.args.read_only: - save_config = True - - elif section and option: - # Display a single key - print_config(section, option) - - elif section: - # Display an entire section - for key in cli.config[section]: - print_config(section, key) - - # Ending actions - if save_config: - cli.save_config() - - return True diff --git a/lib/python/qmk/cli/doctor/linux.py b/lib/python/qmk/cli/doctor/linux.py index 777b19f762..94683d3307 100644 --- a/lib/python/qmk/cli/doctor/linux.py +++ b/lib/python/qmk/cli/doctor/linux.py @@ -54,10 +54,7 @@ def check_udev_rules(): _udev_rule("03eb", "2ff3"), # ATmega16U4 _udev_rule("03eb", "2ff4"), # ATmega32U4 _udev_rule("03eb", "2ff9"), # AT90USB64 -<<<<<<< HEAD -======= _udev_rule("03eb", "2ffa"), # AT90USB162 ->>>>>>> 0.12.52~1 _udev_rule("03eb", "2ffb") # AT90USB128 }, 'kiibohd': {_udev_rule("1c11", "b007")}, @@ -108,11 +105,7 @@ def check_udev_rules(): # Collect all rules from the config files for rule_file in udev_rules: -<<<<<<< HEAD - for line in rule_file.read_text().split('\n'): -======= for line in rule_file.read_text(encoding='utf-8').split('\n'): ->>>>>>> 0.12.52~1 line = line.strip() if not line.startswith("#") and len(line): current_rules.add(line) @@ -149,11 +142,7 @@ def check_modem_manager(): """ if check_systemd(): -<<<<<<< HEAD - mm_check = run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10) -======= mm_check = cli.run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10) ->>>>>>> 0.12.52~1 if mm_check.returncode == 0: return True else: diff --git a/lib/python/qmk/cli/format/c.py b/lib/python/qmk/cli/format/c.py index 568684ed56..8eb7fa1ed0 100644 --- a/lib/python/qmk/cli/format/c.py +++ b/lib/python/qmk/cli/format/c.py @@ -1,6 +1,5 @@ """Format C code according to QMK's style. """ -from os import path from shutil import which from subprocess import CalledProcessError, DEVNULL, Popen, PIPE @@ -15,6 +14,12 @@ core_dirs = ('drivers', 'quantum', 'tests', 'tmk_core', 'platforms') ignored = ('tmk_core/protocol/usb_hid', 'platforms/chibios/boards') +def is_relative_to(file, other): + """Provide similar behavior to PurePath.is_relative_to in Python > 3.9 + """ + return str(normpath(file).resolve()).startswith(str(normpath(other).resolve())) + + def find_clang_format(): """Returns the path to clang-format. """ @@ -68,18 +73,18 @@ def cformat_run(files): def filter_files(files, core_only=False): """Yield only files to be formatted and skip the rest """ - if core_only: - # Filter non-core files - for index, file in enumerate(files): + files = list(map(normpath, filter(None, files))) + + for file in files: + if core_only: # The following statement checks each file to see if the file path is # - in the core directories # - not in the ignored directories - if not any(str(file).startswith(i) for i in core_dirs) or any(str(file).startswith(i) for i in ignored): - files[index] = None + if not any(is_relative_to(file, i) for i in core_dirs) or any(is_relative_to(file, i) for i in ignored): cli.log.debug("Skipping non-core file %s, as '--core-only' is used.", file) + continue - for file in files: - if file and file.name.split('.')[-1] in c_file_suffixes: + if file.suffix[1:] in c_file_suffixes: yield file else: cli.log.debug('Skipping file %s', file) @@ -118,12 +123,8 @@ def format_c(cli): print(git_diff.stderr) return git_diff.returncode - files = [] - - for file in git_diff.stdout.strip().split('\n'): - if not any([file.startswith(ignore) for ignore in ignored]): - if path.exists(file) and file.split('.')[-1] in c_file_suffixes: - files.append(file) + changed_files = git_diff.stdout.strip().split('\n') + files = list(filter_files(changed_files, True)) # Sanity check if not files: diff --git a/lib/python/qmk/cli/format/python.py b/lib/python/qmk/cli/format/python.py index 47b5c45fd5..008622cac1 100755 --- a/lib/python/qmk/cli/format/python.py +++ b/lib/python/qmk/cli/format/python.py @@ -25,8 +25,9 @@ def yapf_run(files): def filter_files(files): """Yield only files to be formatted and skip the rest """ + files = list(map(normpath, filter(None, files))) for file in files: - if file and normpath(file).name.split('.')[-1] in py_file_suffixes: + if file.suffix[1:] in py_file_suffixes: yield file else: cli.log.debug('Skipping file %s', file) diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 602635270c..7ac0f740fe 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -26,7 +26,8 @@ def system_libs(binary: str) -> List[Path]: # Actually query xxxxxx-gcc to find its include paths. if binary.endswith("gcc") or binary.endswith("g++"): - result = cli.run([binary, '-E', '-Wp,-v', '-'], capture_output=True, check=True, input='\n') + # (TODO): Remove 'stdin' once 'input' no longer causes issues under MSYS + result = cli.run([binary, '-E', '-Wp,-v', '-'], capture_output=True, check=True, stdin=None, input='\n') paths = [] for line in result.stderr.splitlines(): if line.startswith(" "): diff --git a/lib/python/qmk/cli/json/__init__.py b/lib/python/qmk/cli/json/__init__.py deleted file mode 100644 index f4ebfc45b4..0000000000 --- a/lib/python/qmk/cli/json/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""QMK CLI JSON Subcommands - -We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup. -""" -from . import keymap diff --git a/lib/python/qmk/cli/json/keymap.py b/lib/python/qmk/cli/json/keymap.py deleted file mode 100755 index 2af9faaa72..0000000000 --- a/lib/python/qmk/cli/json/keymap.py +++ /dev/null @@ -1,16 +0,0 @@ -"""Generate a keymap.c from a configurator export. -""" -from pathlib import Path - -from milc import cli - - -@cli.argument('-o', '--output', arg_only=True, type=Path, help='File to write to') -@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") -@cli.argument('filename', arg_only=True, help='Configurator JSON file') -@cli.subcommand('Creates a keymap.c from a QMK Configurator export.', hidden=True) -def json_keymap(cli): - """Renamed to `qmk json2c`. - """ - cli.log.error('This command has been renamed to `qmk json2c`.') - return False diff --git a/lib/python/qmk/cli/pytest.py b/lib/python/qmk/cli/pytest.py index 2e4a0a9f00..b7b17f0e9d 100644 --- a/lib/python/qmk/cli/pytest.py +++ b/lib/python/qmk/cli/pytest.py @@ -12,7 +12,8 @@ from milc import cli def pytest(cli): """Run several linting/testing commands. """ - nose2 = cli.run(['nose2', '-v', '-t' 'lib/python', *cli.args.test], capture_output=False, stdin=DEVNULL) + nose2 = cli.run(['nose2', '-v', '-t' + 'lib/python', *cli.args.test], capture_output=False, stdin=DEVNULL) flake8 = cli.run(['flake8', 'lib/python'], capture_output=False, stdin=DEVNULL) return flake8.returncode | nose2.returncode diff --git a/lib/python/qmk/constants.py b/lib/python/qmk/constants.py index 754091a97e..433b110523 100644 --- a/lib/python/qmk/constants.py +++ b/lib/python/qmk/constants.py @@ -13,7 +13,7 @@ QMK_FIRMWARE_UPSTREAM = 'qmk/qmk_firmware' MAX_KEYBOARD_SUBFOLDERS = 5 # Supported processor types -CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK66FX1M0', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32L412', 'STM32L422', 'STM32L433', 'STM32L443', 'GD32VF103', 'WB32F3G71' +CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK66FX1M0', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F405', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32L412', 'STM32L422', 'STM32L433', 'STM32L443', 'GD32VF103', 'WB32F3G71' LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85' diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index 2aa1916f55..72bae59273 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -15,6 +15,7 @@ def is_keyboard(keyboard_name): if keyboard_name: keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name rules_mk = keyboard_path / 'rules.mk' + return rules_mk.exists() diff --git a/lib/python/qmk/tests/onekey_export.json b/lib/python/qmk/tests/onekey_export.json deleted file mode 100644 index 95f0a980fe..0000000000 --- a/lib/python/qmk/tests/onekey_export.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "keyboard":"handwired/onekey/pytest", - "keymap":"pytest_unittest", - "layout":"LAYOUT", - "layers":[["KC_A"]] -} diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 2973f81702..92ec879312 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -113,21 +113,21 @@ def test_list_keymaps_community(): def test_list_keymaps_kb_only(): - result = check_subcommand('list-keymaps', '-kb', 'niu_mini') + result = check_subcommand('list-keymaps', '-kb', 'moonlander') check_returncode(result) - assert 'default' and 'via' in result.stdout + assert 'default' and 'oyrx' and 'webusb' in result.stdout def test_list_keymaps_vendor_kb(): - result = check_subcommand('list-keymaps', '-kb', 'ai03/lunar') + result = check_subcommand('list-keymaps', '-kb', 'planck/ez') check_returncode(result) - assert 'default' and 'via' in result.stdout + assert 'default' and 'oryx' and 'webusb' in result.stdout -def test_list_keymaps_vendor_kb_rev(): - result = check_subcommand('list-keymaps', '-kb', 'kbdfans/kbd67/mkiirgb/v2') - check_returncode(result) - assert 'default' and 'via' in result.stdout +# def test_list_keymaps_vendor_kb_rev(): +# result = check_subcommand('list-keymaps', '-kb', 'kbdfans/kbd67/mkiirgb/v2') +# check_returncode(result) +# assert 'default' and 'via' in result.stdout def test_list_keymaps_no_keyboard_found(): |