aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r--lib/python/qmk/cli/cformat.py10
-rw-r--r--lib/python/qmk/cli/clean.py6
-rwxr-xr-xlib/python/qmk/cli/compile.py5
-rwxr-xr-xlib/python/qmk/cli/doctor.py4
-rw-r--r--lib/python/qmk/cli/flash.py5
-rw-r--r--lib/python/qmk/cli/generate/docs.py14
-rwxr-xr-xlib/python/qmk/cli/multibuild.py5
-rw-r--r--lib/python/qmk/cli/new/keyboard.py2
-rwxr-xr-xlib/python/qmk/cli/pyformat.py8
-rw-r--r--lib/python/qmk/cli/pytest.py6
10 files changed, 36 insertions, 29 deletions
diff --git a/lib/python/qmk/cli/cformat.py b/lib/python/qmk/cli/cformat.py
index 15158d9c7..efeb45967 100644
--- a/lib/python/qmk/cli/cformat.py
+++ b/lib/python/qmk/cli/cformat.py
@@ -1,8 +1,8 @@
1"""Format C code according to QMK's style. 1"""Format C code according to QMK's style.
2""" 2"""
3import subprocess
4from os import path 3from os import path
5from shutil import which 4from shutil import which
5from subprocess import CalledProcessError, DEVNULL, Popen, PIPE
6 6
7from argcomplete.completers import FilesCompleter 7from argcomplete.completers import FilesCompleter
8from milc import cli 8from milc import cli
@@ -34,7 +34,7 @@ def find_diffs(files):
34 34
35 for file in files: 35 for file in files:
36 cli.log.debug('Checking for changes in %s', file) 36 cli.log.debug('Checking for changes in %s', file)
37 clang_format = subprocess.Popen([find_clang_format(), file], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) 37 clang_format = Popen([find_clang_format(), file], stdout=PIPE, stderr=PIPE, universal_newlines=True)
38 diff = cli.run(['diff', '-u', f'--label=a/{file}', f'--label=b/{file}', str(file), '-'], stdin=clang_format.stdout, capture_output=True) 38 diff = cli.run(['diff', '-u', f'--label=a/{file}', f'--label=b/{file}', str(file), '-'], stdin=clang_format.stdout, capture_output=True)
39 39
40 if diff.returncode != 0: 40 if diff.returncode != 0:
@@ -51,11 +51,11 @@ def cformat_run(files):
51 clang_format = [find_clang_format(), '-i'] 51 clang_format = [find_clang_format(), '-i']
52 52
53 try: 53 try:
54 cli.run(clang_format + list(map(str, files)), check=True, capture_output=False) 54 cli.run([*clang_format, *map(str, files)], check=True, capture_output=False, stdin=DEVNULL)
55 cli.log.info('Successfully formatted the C code.') 55 cli.log.info('Successfully formatted the C code.')
56 return True 56 return True
57 57
58 except subprocess.CalledProcessError as e: 58 except CalledProcessError as e:
59 cli.log.error('Error formatting C code!') 59 cli.log.error('Error formatting C code!')
60 cli.log.debug('%s exited with returncode %s', e.cmd, e.returncode) 60 cli.log.debug('%s exited with returncode %s', e.cmd, e.returncode)
61 cli.log.debug('STDOUT:') 61 cli.log.debug('STDOUT:')
@@ -111,7 +111,7 @@ def cformat(cli):
111 111
112 else: 112 else:
113 git_diff_cmd = ['git', 'diff', '--name-only', cli.args.base_branch, *core_dirs] 113 git_diff_cmd = ['git', 'diff', '--name-only', cli.args.base_branch, *core_dirs]
114 git_diff = cli.run(git_diff_cmd) 114 git_diff = cli.run(git_diff_cmd, stdin=DEVNULL)
115 115
116 if git_diff.returncode != 0: 116 if git_diff.returncode != 0:
117 cli.log.error("Error running %s", git_diff_cmd) 117 cli.log.error("Error running %s", git_diff_cmd)
diff --git a/lib/python/qmk/cli/clean.py b/lib/python/qmk/cli/clean.py
index 9096529fd..72b7ffe81 100644
--- a/lib/python/qmk/cli/clean.py
+++ b/lib/python/qmk/cli/clean.py
@@ -1,6 +1,8 @@
1"""Clean the QMK firmware folder of build artifacts. 1"""Clean the QMK firmware folder of build artifacts.
2""" 2"""
3from qmk.commands import run, create_make_target 3from subprocess import DEVNULL
4
5from qmk.commands import create_make_target
4from milc import cli 6from milc import cli
5 7
6 8
@@ -9,4 +11,4 @@ from milc import cli
9def clean(cli): 11def clean(cli):
10 """Runs `make clean` (or `make distclean` if --all is passed) 12 """Runs `make clean` (or `make distclean` if --all is passed)
11 """ 13 """
12 run(create_make_target('distclean' if cli.args.all else 'clean')) 14 cli.run(create_make_target('distclean' if cli.args.all else 'clean'), capture_output=False, stdin=DEVNULL)
diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py
index 23ca4e00a..7a45e7721 100755
--- a/lib/python/qmk/cli/compile.py
+++ b/lib/python/qmk/cli/compile.py
@@ -2,6 +2,8 @@
2 2
3You can compile a keymap already in the repo or using a QMK Configurator export. 3You can compile a keymap already in the repo or using a QMK Configurator export.
4""" 4"""
5from subprocess import DEVNULL
6
5from argcomplete.completers import FilesCompleter 7from argcomplete.completers import FilesCompleter
6from milc import cli 8from milc import cli
7 9
@@ -31,8 +33,7 @@ def compile(cli):
31 """ 33 """
32 if cli.args.clean and not cli.args.filename and not cli.args.dry_run: 34 if cli.args.clean and not cli.args.filename and not cli.args.dry_run:
33 command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, 'clean') 35 command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, 'clean')
34 # FIXME(skullydazed/anyone): Remove text=False once milc 1.0.11 has had enough time to be installed everywhere. 36 cli.run(command, capture_output=False, stdin=DEVNULL)
35 cli.run(command, capture_output=False, text=False)
36 37
37 # Build the environment vars 38 # Build the environment vars
38 envs = {} 39 envs = {}
diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py
index 4a2e2010f..9e1057062 100755
--- a/lib/python/qmk/cli/doctor.py
+++ b/lib/python/qmk/cli/doctor.py
@@ -3,12 +3,12 @@
3Check out the user's QMK environment and make sure it's ready to compile. 3Check out the user's QMK environment and make sure it's ready to compile.
4""" 4"""
5import platform 5import platform
6from subprocess import DEVNULL
6 7
7from milc import cli 8from milc import cli
8from milc.questions import yesno 9from milc.questions import yesno
9from qmk import submodules 10from qmk import submodules
10from qmk.constants import QMK_FIRMWARE 11from qmk.constants import QMK_FIRMWARE
11from qmk.commands import run
12from qmk.os_helpers import CheckStatus, check_binaries, check_binary_versions, check_submodules, check_git_repo 12from qmk.os_helpers import CheckStatus, check_binaries, check_binary_versions, check_submodules, check_git_repo
13 13
14 14
@@ -93,7 +93,7 @@ def doctor(cli):
93 93
94 if not bin_ok: 94 if not bin_ok:
95 if yesno('Would you like to install dependencies?', default=True): 95 if yesno('Would you like to install dependencies?', default=True):
96 run(['util/qmk_install.sh']) 96 cli.run(['util/qmk_install.sh', '-y'], stdin=DEVNULL, capture_output=False)
97 bin_ok = check_binaries() 97 bin_ok = check_binaries()
98 98
99 if bin_ok: 99 if bin_ok:
diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py
index 1b6784061..1b2932a5b 100644
--- a/lib/python/qmk/cli/flash.py
+++ b/lib/python/qmk/cli/flash.py
@@ -3,6 +3,7 @@
3You can compile a keymap already in the repo or using a QMK Configurator export. 3You can compile a keymap already in the repo or using a QMK Configurator export.
4A bootloader must be specified. 4A bootloader must be specified.
5""" 5"""
6from subprocess import DEVNULL
6 7
7from argcomplete.completers import FilesCompleter 8from argcomplete.completers import FilesCompleter
8from milc import cli 9from milc import cli
@@ -55,7 +56,7 @@ def flash(cli):
55 """ 56 """
56 if cli.args.clean and not cli.args.filename and not cli.args.dry_run: 57 if cli.args.clean and not cli.args.filename and not cli.args.dry_run:
57 command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, 'clean') 58 command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, 'clean')
58 cli.run(command, capture_output=False) 59 cli.run(command, capture_output=False, stdin=DEVNULL)
59 60
60 # Build the environment vars 61 # Build the environment vars
61 envs = {} 62 envs = {}
@@ -98,7 +99,7 @@ def flash(cli):
98 cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command)) 99 cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command))
99 if not cli.args.dry_run: 100 if not cli.args.dry_run:
100 cli.echo('\n') 101 cli.echo('\n')
101 compile = cli.run(command, capture_output=False, text=True) 102 compile = cli.run(command, capture_output=False, stdin=DEVNULL)
102 return compile.returncode 103 return compile.returncode
103 104
104 else: 105 else:
diff --git a/lib/python/qmk/cli/generate/docs.py b/lib/python/qmk/cli/generate/docs.py
index a59a24db5..749336fea 100644
--- a/lib/python/qmk/cli/generate/docs.py
+++ b/lib/python/qmk/cli/generate/docs.py
@@ -1,8 +1,8 @@
1"""Build QMK documentation locally 1"""Build QMK documentation locally
2""" 2"""
3import shutil 3import shutil
4import subprocess
5from pathlib import Path 4from pathlib import Path
5from subprocess import DEVNULL
6 6
7from milc import cli 7from milc import cli
8 8
@@ -24,14 +24,16 @@ def generate_docs(cli):
24 shutil.copytree(DOCS_PATH, BUILD_PATH) 24 shutil.copytree(DOCS_PATH, BUILD_PATH)
25 25
26 # When not verbose we want to hide all output 26 # When not verbose we want to hide all output
27 args = {'check': True} 27 args = {
28 if not cli.args.verbose: 28 'capture_output': False if cli.config.general.verbose else True,
29 args.update({'stdout': subprocess.DEVNULL, 'stderr': subprocess.STDOUT}) 29 'check': True,
30 'stdin': DEVNULL,
31 }
30 32
31 cli.log.info('Generating internal docs...') 33 cli.log.info('Generating internal docs...')
32 34
33 # Generate internal docs 35 # Generate internal docs
34 subprocess.run(['doxygen', 'Doxyfile'], **args) 36 cli.run(['doxygen', 'Doxyfile'], **args)
35 subprocess.run(['moxygen', '-q', '-a', '-g', '-o', BUILD_PATH / 'internals_%s.md', 'doxygen/xml'], **args) 37 cli.run(['moxygen', '-q', '-a', '-g', '-o', BUILD_PATH / 'internals_%s.md', 'doxygen/xml'], **args)
36 38
37 cli.log.info('Successfully generated internal docs to %s.', BUILD_PATH) 39 cli.log.info('Successfully generated internal docs to %s.', BUILD_PATH)
diff --git a/lib/python/qmk/cli/multibuild.py b/lib/python/qmk/cli/multibuild.py
index a4f0a0cc0..46594c099 100755
--- a/lib/python/qmk/cli/multibuild.py
+++ b/lib/python/qmk/cli/multibuild.py
@@ -4,6 +4,7 @@ This will compile everything in parallel, for testing purposes.
4""" 4"""
5import re 5import re
6from pathlib import Path 6from pathlib import Path
7from subprocess import DEVNULL
7 8
8from milc import cli 9from milc import cli
9 10
@@ -35,7 +36,7 @@ def multibuild(cli):
35 36
36 make_cmd = _find_make() 37 make_cmd = _find_make()
37 if cli.args.clean: 38 if cli.args.clean:
38 cli.run([make_cmd, 'clean'], capture_output=False, text=False) 39 cli.run([make_cmd, 'clean'], capture_output=False, stdin=DEVNULL)
39 40
40 builddir = Path(QMK_FIRMWARE) / '.build' 41 builddir = Path(QMK_FIRMWARE) / '.build'
41 makefile = builddir / 'parallel_kb_builds.mk' 42 makefile = builddir / 'parallel_kb_builds.mk'
@@ -75,4 +76,4 @@ all: {keyboard_safe}_binary
75 ) 76 )
76 # yapf: enable 77 # yapf: enable
77 78
78 cli.run([make_cmd, '-j', str(cli.args.parallel), '-f', makefile, 'all'], capture_output=False, text=False) 79 cli.run([make_cmd, '-j', str(cli.args.parallel), '-f', makefile, 'all'], capture_output=False, stdin=DEVNULL)
diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py
index cab0198fb..ae4445ca4 100644
--- a/lib/python/qmk/cli/new/keyboard.py
+++ b/lib/python/qmk/cli/new/keyboard.py
@@ -8,4 +8,4 @@ def new_keyboard(cli):
8 """Creates a new keyboard 8 """Creates a new keyboard
9 """ 9 """
10 # TODO: replace this bodge to the existing script 10 # TODO: replace this bodge to the existing script
11 cli.run(['util/new_keyboard.sh'], capture_output=False) 11 cli.run(['util/new_keyboard.sh'], stdin=None, capture_output=False)
diff --git a/lib/python/qmk/cli/pyformat.py b/lib/python/qmk/cli/pyformat.py
index 02581f0d8..abe5f6de1 100755
--- a/lib/python/qmk/cli/pyformat.py
+++ b/lib/python/qmk/cli/pyformat.py
@@ -1,8 +1,8 @@
1"""Format python code according to QMK's style. 1"""Format python code according to QMK's style.
2""" 2"""
3from milc import cli 3from subprocess import CalledProcessError, DEVNULL
4 4
5import subprocess 5from milc import cli
6 6
7 7
8@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Flag only, don't automatically format.") 8@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Flag only, don't automatically format.")
@@ -13,11 +13,11 @@ def pyformat(cli):
13 edit = '--diff' if cli.args.dry_run else '--in-place' 13 edit = '--diff' if cli.args.dry_run else '--in-place'
14 yapf_cmd = ['yapf', '-vv', '--recursive', edit, 'bin/qmk', 'lib/python'] 14 yapf_cmd = ['yapf', '-vv', '--recursive', edit, 'bin/qmk', 'lib/python']
15 try: 15 try:
16 cli.run(yapf_cmd, check=True, capture_output=False) 16 cli.run(yapf_cmd, check=True, capture_output=False, stdin=DEVNULL)
17 cli.log.info('Python code in `bin/qmk` and `lib/python` is correctly formatted.') 17 cli.log.info('Python code in `bin/qmk` and `lib/python` is correctly formatted.')
18 return True 18 return True
19 19
20 except subprocess.CalledProcessError: 20 except CalledProcessError:
21 if cli.args.dry_run: 21 if cli.args.dry_run:
22 cli.log.error('Python code in `bin/qmk` and `lib/python` incorrectly formatted!') 22 cli.log.error('Python code in `bin/qmk` and `lib/python` incorrectly formatted!')
23 else: 23 else:
diff --git a/lib/python/qmk/cli/pytest.py b/lib/python/qmk/cli/pytest.py
index 50a1d70a4..bdb336b9a 100644
--- a/lib/python/qmk/cli/pytest.py
+++ b/lib/python/qmk/cli/pytest.py
@@ -2,7 +2,7 @@
2 2
3QMK script to run unit and integration tests against our python code. 3QMK script to run unit and integration tests against our python code.
4""" 4"""
5import subprocess 5from subprocess import DEVNULL
6 6
7from milc import cli 7from milc import cli
8 8
@@ -11,7 +11,7 @@ from milc import cli
11def pytest(cli): 11def pytest(cli):
12 """Run several linting/testing commands. 12 """Run several linting/testing commands.
13 """ 13 """
14 nose2 = subprocess.run(['nose2', '-v']) 14 nose2 = cli.run(['nose2', '-v'], capture_output=False, stdin=DEVNULL)
15 flake8 = subprocess.run(['flake8', 'lib/python', 'bin/qmk']) 15 flake8 = cli.run(['flake8', 'lib/python', 'bin/qmk'], capture_output=False, stdin=DEVNULL)
16 16
17 return flake8.returncode | nose2.returncode 17 return flake8.returncode | nose2.returncode