From a25dd58bc56b0c4010673723ac44eaff914979bb Mon Sep 17 00:00:00 2001 From: skullydazed Date: Mon, 15 Jul 2019 12:14:27 -0700 Subject: QMK CLI and JSON keymap support (#6176) * Script to generate keymap.c from JSON file. * Support for keymap.json * Add a warning about the keymap.c getting overwritten. * Fix keymap generating * Install the python deps * Flesh out more of the python environment * Remove defunct json2keymap * Style everything with yapf * Polish up python support * Hide json keymap.c into the .build dir * Polish up qmk-compile-json * Make milc work with positional arguments * Fix a couple small things * Fix some errors and make the CLI more understandable * Make the qmk wrapper more robust * Add basic QMK Doctor * Clean up docstrings and flesh them out as needed * remove unused compile_firmware() function --- lib/python/qmk/cli/doctor.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 lib/python/qmk/cli/doctor.py (limited to 'lib/python/qmk/cli/doctor.py') diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py new file mode 100755 index 0000000000..9ce765a4b5 --- /dev/null +++ b/lib/python/qmk/cli/doctor.py @@ -0,0 +1,47 @@ +"""QMK Python Doctor + +Check up for QMK environment. +""" +import shutil +import platform +import os + +from milc import cli + + +@cli.entrypoint('Basic QMK environment checks') +def main(cli): + """Basic QMK environment checks. + + This is currently very simple, it just checks that all the expected binaries are on your system. + + TODO(unclaimed): + * [ ] Run the binaries to make sure they work + * [ ] Compile a trivial program with each compiler + * [ ] Check for udev entries on linux + """ + + binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc'] + + cli.log.info('QMK Doctor is Checking your environment') + + ok = True + for binary in binaries: + res = shutil.which(binary) + if res is None: + cli.log.error('{fg_red}QMK can\'t find ' + binary + ' in your path') + ok = False + + OS = platform.system() + if OS == "Darwin": + cli.log.info("Detected {fg_cyan}macOS") + elif OS == "Linux": + cli.log.info("Detected {fg_cyan}linux") + test = 'systemctl list-unit-files | grep enabled | grep -i ModemManager' + if os.system(test) == 0: + cli.log.warn("{bg_yellow}Detected modem manager. Please disable it if you are using Pro Micros") + else: + cli.log.info("Assuming {fg_cyan}Windows") + + if ok: + cli.log.info('{fg_green}QMK is ready to go') -- cgit v1.2.3 From 5b7a5b2a7629fbb667d23a55836dce3c6c46a203 Mon Sep 17 00:00:00 2001 From: skullY Date: Wed, 21 Aug 2019 23:40:24 -0700 Subject: Setup a python test framework --- lib/python/qmk/cli/doctor.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'lib/python/qmk/cli/doctor.py') diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index 9ce765a4b5..c5a144363c 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py @@ -2,9 +2,11 @@ Check up for QMK environment. """ -import shutil -import platform import os +import platform +import shutil +import subprocess +from glob import glob from milc import cli @@ -16,32 +18,44 @@ def main(cli): This is currently very simple, it just checks that all the expected binaries are on your system. TODO(unclaimed): - * [ ] Run the binaries to make sure they work * [ ] Compile a trivial program with each compiler * [ ] Check for udev entries on linux """ binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc'] + binaries += glob('bin/qmk-*') - cli.log.info('QMK Doctor is Checking your environment') + cli.log.info('QMK Doctor is checking your environment') ok = True for binary in binaries: res = shutil.which(binary) if res is None: - cli.log.error('{fg_red}QMK can\'t find ' + binary + ' in your path') + cli.log.error("{fg_red}QMK can't find %s in your path", binary) ok = False + else: + try: + subprocess.run([binary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5, check=True) + except subprocess.CalledProcessError: + cli.log.error("{fg_red}Can't run `%s --version`", binary) + ok = False OS = platform.system() if OS == "Darwin": cli.log.info("Detected {fg_cyan}macOS") elif OS == "Linux": cli.log.info("Detected {fg_cyan}linux") - test = 'systemctl list-unit-files | grep enabled | grep -i ModemManager' - if os.system(test) == 0: - cli.log.warn("{bg_yellow}Detected modem manager. Please disable it if you are using Pro Micros") + if shutil.which('systemctl'): + test = 'systemctl list-unit-files | grep enabled | grep -i ModemManager' + if os.system(test) == 0: + cli.log.warn("{bg_yellow}Detected modem manager. Please disable it if you are using Pro Micros") + else: + cli.log.warn("Can't find systemctl to check for ModemManager.") else: cli.log.info("Assuming {fg_cyan}Windows") if ok: cli.log.info('{fg_green}QMK is ready to go') + else: + cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.') + # FIXME(skullydazed): Link to a document about troubleshooting, or discord or something -- cgit v1.2.3 From 533d6d6a464d41d23a39cecfe42d95d2e400d335 Mon Sep 17 00:00:00 2001 From: skullY Date: Thu, 22 Aug 2019 09:38:10 -0700 Subject: Make the modem manager check more pythonic --- lib/python/qmk/cli/doctor.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'lib/python/qmk/cli/doctor.py') diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index c5a144363c..5a713b20f5 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py @@ -21,17 +21,17 @@ def main(cli): * [ ] Compile a trivial program with each compiler * [ ] Check for udev entries on linux """ + cli.log.info('QMK Doctor is checking your environment.') + # Make sure the basic CLI tools we need are available and can be executed. binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc'] binaries += glob('bin/qmk-*') - - cli.log.info('QMK Doctor is checking your environment') - ok = True + for binary in binaries: res = shutil.which(binary) if res is None: - cli.log.error("{fg_red}QMK can't find %s in your path", binary) + cli.log.error("{fg_red}QMK can't find %s in your path.", binary) ok = False else: try: @@ -40,20 +40,36 @@ def main(cli): cli.log.error("{fg_red}Can't run `%s --version`", binary) ok = False + # Determine our OS and run platform specific tests OS = platform.system() + if OS == "Darwin": - cli.log.info("Detected {fg_cyan}macOS") + cli.log.info("Detected {fg_cyan}macOS.") + elif OS == "Linux": - cli.log.info("Detected {fg_cyan}linux") + cli.log.info("Detected {fg_cyan}Linux.") if shutil.which('systemctl'): - test = 'systemctl list-unit-files | grep enabled | grep -i ModemManager' - if os.system(test) == 0: - cli.log.warn("{bg_yellow}Detected modem manager. Please disable it if you are using Pro Micros") + mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) + if mm_check.returncode == 0: + mm = True + for line in mm_check.stdout.split('\n'): + if 'ModemManager' in line and 'enabled' in line: + mm = False + + if mm: + cli.log.warn("{bg_yellow}Detected ModemManager. Please disable it if you are using a Pro-Micro.") + + else: + cli.log.error('{bg_red}Could not run `systemctl list-unit-files`:') + cli.log.error(mm_check.stderr) + else: cli.log.warn("Can't find systemctl to check for ModemManager.") + else: - cli.log.info("Assuming {fg_cyan}Windows") + cli.log.info("Assuming {fg_cyan}Windows.") + # Report a summary of our findings to the user if ok: cli.log.info('{fg_green}QMK is ready to go') else: -- cgit v1.2.3 From d569f0877155efc752994f8a21f5cf001f9d6ae6 Mon Sep 17 00:00:00 2001 From: skullydazed Date: Sun, 22 Sep 2019 13:25:33 -0700 Subject: Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick * Apply suggestions from code review Co-Authored-By: Noah Frederick * Remove pip3 from the test runner --- lib/python/qmk/cli/doctor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/python/qmk/cli/doctor.py') diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index 5a713b20f5..3474422a89 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py @@ -11,8 +11,8 @@ from glob import glob from milc import cli -@cli.entrypoint('Basic QMK environment checks') -def main(cli): +@cli.subcommand('Basic QMK environment checks') +def doctor(cli): """Basic QMK environment checks. This is currently very simple, it just checks that all the expected binaries are on your system. @@ -36,6 +36,7 @@ def main(cli): else: try: subprocess.run([binary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5, check=True) + cli.log.info('Found {fg_cyan}%s', binary) except subprocess.CalledProcessError: cli.log.error("{fg_red}Can't run `%s --version`", binary) ok = False -- cgit v1.2.3 From 9067dc817aefb7fe43d23a995604555642c6c897 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 1 Oct 2019 20:56:16 -0400 Subject: Fix qmk doctor 'bytes-like object is required' on linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the following issue related to encoding on linux systems. Add `universal_newlines=True` to subprocess. ☒ a bytes-like object is required, not 'str' Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/milc.py", line 564, in __call__ return self.__call__() File "/usr/local/lib/python3.7/site-packages/milc.py", line 569, in __call__ return self._entrypoint(self) File "$HOME/qmk_firmware/lib/python/qmk/cli/doctor.py", line 56, in doctor for line in mm_check.stdout.split('\n'): TypeError: a bytes-like object is required, not 'str' --- lib/python/qmk/cli/doctor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/python/qmk/cli/doctor.py') diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index 3474422a89..2b6a03e443 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py @@ -50,7 +50,7 @@ def doctor(cli): elif OS == "Linux": cli.log.info("Detected {fg_cyan}Linux.") if shutil.which('systemctl'): - mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) + mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10, universal_newlines=True) if mm_check.returncode == 0: mm = True for line in mm_check.stdout.split('\n'): -- cgit v1.2.3 From f64d9b06215bb08d7f77aeba126c0804fffd0064 Mon Sep 17 00:00:00 2001 From: Harry Wada Date: Sun, 20 Oct 2019 09:33:58 -0500 Subject: Fix detection of ModemManager (#7076) --- lib/python/qmk/cli/doctor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/python/qmk/cli/doctor.py') diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index 2b6a03e443..309de0c671 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py @@ -52,10 +52,10 @@ def doctor(cli): if shutil.which('systemctl'): mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10, universal_newlines=True) if mm_check.returncode == 0: - mm = True + mm = False for line in mm_check.stdout.split('\n'): if 'ModemManager' in line and 'enabled' in line: - mm = False + mm = True if mm: cli.log.warn("{bg_yellow}Detected ModemManager. Please disable it if you are using a Pro-Micro.") -- cgit v1.2.3 From d1b6c11b7f4cc24c50d2b640a94925acf6450da6 Mon Sep 17 00:00:00 2001 From: skullY Date: Tue, 12 Nov 2019 17:21:33 -0800 Subject: When checking program returncodes treat both 0 and 1 as installed --- lib/python/qmk/cli/doctor.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/python/qmk/cli/doctor.py') diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index 309de0c671..c2723bfcbb 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py @@ -24,8 +24,7 @@ def doctor(cli): cli.log.info('QMK Doctor is checking your environment.') # Make sure the basic CLI tools we need are available and can be executed. - binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc'] - binaries += glob('bin/qmk-*') + binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc', 'bin/qmk'] ok = True for binary in binaries: @@ -34,10 +33,10 @@ def doctor(cli): cli.log.error("{fg_red}QMK can't find %s in your path.", binary) ok = False else: - try: - subprocess.run([binary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5, check=True) + check = subprocess.run([binary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5) + if check.returncode in [0, 1]: cli.log.info('Found {fg_cyan}%s', binary) - except subprocess.CalledProcessError: + else: cli.log.error("{fg_red}Can't run `%s --version`", binary) ok = False -- cgit v1.2.3 From f7bdc54c697ff24bec1bd0781666ac05401bafb2 Mon Sep 17 00:00:00 2001 From: skullydazed Date: Wed, 20 Nov 2019 14:54:18 -0800 Subject: Add flake8 to our test suite and fix all errors (#7379) * Add flake8 to our test suite and fix all errors * Add some documentation --- lib/python/qmk/cli/doctor.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/python/qmk/cli/doctor.py') diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index c2723bfcbb..1010eafb33 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py @@ -2,11 +2,9 @@ Check up for QMK environment. """ -import os import platform import shutil import subprocess -from glob import glob from milc import cli -- cgit v1.2.3