aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-05-19 15:24:46 -0700
committerGitHub <noreply@github.com>2021-05-19 15:24:46 -0700
commitdb1eacdaacb9c8f6889f46bc1c6af155b81ad72a (patch)
treecd32a69a04c7ff93a11941d82aef3ce31c2b7523 /lib/python/qmk
parenta9aec546c873fa5a2cb1d9a10878aca71818b609 (diff)
downloadqmk_firmware-db1eacdaacb9c8f6889f46bc1c6af155b81ad72a.tar.gz
qmk_firmware-db1eacdaacb9c8f6889f46bc1c6af155b81ad72a.zip
Align our subprocess usage with current best practices. (#12940)
* Align our subprocess usage with current best practices. * remove unused import * Apply suggestions from code review Co-authored-by: Ryan <fauxpark@gmail.com> * fix the cpp invocation for older python * allow for unprompted installation * make sure qmk new-keyboard works on windows Co-authored-by: Ryan <fauxpark@gmail.com>
Diffstat (limited to 'lib/python/qmk')
-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
-rw-r--r--lib/python/qmk/commands.py23
-rw-r--r--lib/python/qmk/keymap.py9
-rw-r--r--lib/python/qmk/os_helpers/__init__.py5
-rw-r--r--lib/python/qmk/os_helpers/linux/__init__.py3
-rw-r--r--lib/python/qmk/submodules.py17
-rw-r--r--lib/python/qmk/tests/test_cli_commands.py9
16 files changed, 58 insertions, 73 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
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py
index 8c3f95ea2..ee049e8af 100644
--- a/lib/python/qmk/commands.py
+++ b/lib/python/qmk/commands.py
@@ -2,11 +2,9 @@
2""" 2"""
3import json 3import json
4import os 4import os
5import platform
6import subprocess
7import shlex
8import shutil 5import shutil
9from pathlib import Path 6from pathlib import Path
7from subprocess import DEVNULL
10from time import strftime 8from time import strftime
11 9
12from milc import cli 10from milc import cli
@@ -94,7 +92,7 @@ def get_git_version(repo_dir='.', check_dir='.'):
94 git_describe_cmd = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags'] 92 git_describe_cmd = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags']
95 93
96 if Path(check_dir).exists(): 94 if Path(check_dir).exists():
97 git_describe = cli.run(git_describe_cmd, cwd=repo_dir) 95 git_describe = cli.run(git_describe_cmd, stdin=DEVNULL, cwd=repo_dir)
98 96
99 if git_describe.returncode == 0: 97 if git_describe.returncode == 0:
100 return git_describe.stdout.strip() 98 return git_describe.stdout.strip()
@@ -224,20 +222,3 @@ def parse_configurator_json(configurator_file):
224 user_keymap['layout'] = aliases[orig_keyboard]['layouts'][user_keymap['layout']] 222 user_keymap['layout'] = aliases[orig_keyboard]['layouts'][user_keymap['layout']]
225 223
226 return user_keymap 224 return user_keymap
227
228
229def run(command, *args, **kwargs):
230 """Run a command with subprocess.run
231 """
232 platform_id = platform.platform().lower()
233
234 if isinstance(command, str):
235 raise TypeError('`command` must be a non-text sequence such as list or tuple.')
236
237 if 'windows' in platform_id:
238 safecmd = map(str, command)
239 safecmd = map(shlex.quote, safecmd)
240 safecmd = ' '.join(safecmd)
241 command = [os.environ.get('SHELL', '/usr/bin/bash'), '-c', safecmd]
242
243 return subprocess.run(command, *args, **kwargs)
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py
index 4ad9ffb59..ac7951082 100644
--- a/lib/python/qmk/keymap.py
+++ b/lib/python/qmk/keymap.py
@@ -1,9 +1,9 @@
1"""Functions that help you work with QMK keymaps. 1"""Functions that help you work with QMK keymaps.
2""" 2"""
3import json 3import json
4import subprocess
5import sys 4import sys
6from pathlib import Path 5from pathlib import Path
6from subprocess import DEVNULL
7 7
8import argcomplete 8import argcomplete
9from milc import cli 9from milc import cli
@@ -12,7 +12,6 @@ from pygments.token import Token
12from pygments import lex 12from pygments import lex
13 13
14import qmk.path 14import qmk.path
15import qmk.commands
16from qmk.keyboard import find_keyboard_from_dir, rules_mk 15from qmk.keyboard import find_keyboard_from_dir, rules_mk
17 16
18# The `keymap.c` template to use when a keyboard doesn't have its own 17# The `keymap.c` template to use when a keyboard doesn't have its own
@@ -361,7 +360,7 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa
361 return sorted(names) 360 return sorted(names)
362 361
363 362
364def _c_preprocess(path, stdin=None): 363def _c_preprocess(path, stdin=DEVNULL):
365 """ Run a file through the C pre-processor 364 """ Run a file through the C pre-processor
366 365
367 Args: 366 Args:
@@ -371,7 +370,9 @@ def _c_preprocess(path, stdin=None):
371 Returns: 370 Returns:
372 the stdout of the pre-processor 371 the stdout of the pre-processor
373 """ 372 """
374 pre_processed_keymap = qmk.commands.run(['cpp', path] if path else ['cpp'], stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) 373 cmd = ['cpp', str(path)] if path else ['cpp']
374 pre_processed_keymap = cli.run(cmd, stdin=stdin)
375
375 return pre_processed_keymap.stdout 376 return pre_processed_keymap.stdout
376 377
377 378
diff --git a/lib/python/qmk/os_helpers/__init__.py b/lib/python/qmk/os_helpers/__init__.py
index 3f64a63a3..3e98db3c3 100644
--- a/lib/python/qmk/os_helpers/__init__.py
+++ b/lib/python/qmk/os_helpers/__init__.py
@@ -3,10 +3,9 @@
3from enum import Enum 3from enum import Enum
4import re 4import re
5import shutil 5import shutil
6import subprocess 6from subprocess import DEVNULL
7 7
8from milc import cli 8from milc import cli
9from qmk.commands import run
10from qmk import submodules 9from qmk import submodules
11from qmk.constants import QMK_FIRMWARE 10from qmk.constants import QMK_FIRMWARE
12 11
@@ -142,7 +141,7 @@ def is_executable(command):
142 141
143 # Make sure the command can be executed 142 # Make sure the command can be executed
144 version_arg = ESSENTIAL_BINARIES[command].get('version_arg', '--version') 143 version_arg = ESSENTIAL_BINARIES[command].get('version_arg', '--version')
145 check = run([command, version_arg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=5, universal_newlines=True) 144 check = cli.run([command, version_arg], combined_output=True, stdin=DEVNULL, timeout=5)
146 145
147 ESSENTIAL_BINARIES[command]['output'] = check.stdout 146 ESSENTIAL_BINARIES[command]['output'] = check.stdout
148 147
diff --git a/lib/python/qmk/os_helpers/linux/__init__.py b/lib/python/qmk/os_helpers/linux/__init__.py
index 9e73964e4..008654ab0 100644
--- a/lib/python/qmk/os_helpers/linux/__init__.py
+++ b/lib/python/qmk/os_helpers/linux/__init__.py
@@ -5,7 +5,6 @@ import shutil
5 5
6from milc import cli 6from milc import cli
7from qmk.constants import QMK_FIRMWARE 7from qmk.constants import QMK_FIRMWARE
8from qmk.commands import run
9from qmk.os_helpers import CheckStatus 8from qmk.os_helpers import CheckStatus
10 9
11 10
@@ -132,7 +131,7 @@ def check_modem_manager():
132 131
133 """ 132 """
134 if check_systemd(): 133 if check_systemd():
135 mm_check = run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10) 134 mm_check = cli.run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10)
136 if mm_check.returncode == 0: 135 if mm_check.returncode == 0:
137 return True 136 return True
138 else: 137 else:
diff --git a/lib/python/qmk/submodules.py b/lib/python/qmk/submodules.py
index be51a6804..6a272dae5 100644
--- a/lib/python/qmk/submodules.py
+++ b/lib/python/qmk/submodules.py
@@ -1,7 +1,6 @@
1"""Functions for working with QMK's submodules. 1"""Functions for working with QMK's submodules.
2""" 2"""
3 3from milc import cli
4import subprocess
5 4
6 5
7def status(): 6def status():
@@ -18,7 +17,7 @@ def status():
18 status is None when the submodule doesn't exist, False when it's out of date, and True when it's current 17 status is None when the submodule doesn't exist, False when it's out of date, and True when it's current
19 """ 18 """
20 submodules = {} 19 submodules = {}
21 git_cmd = subprocess.run(['git', 'submodule', 'status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=30, universal_newlines=True) 20 git_cmd = cli.run(['git', 'submodule', 'status'], timeout=30)
22 21
23 for line in git_cmd.stdout.split('\n'): 22 for line in git_cmd.stdout.split('\n'):
24 if not line: 23 if not line:
@@ -53,19 +52,19 @@ def update(submodules=None):
53 # Update everything 52 # Update everything
54 git_sync_cmd.append('--recursive') 53 git_sync_cmd.append('--recursive')
55 git_update_cmd.append('--recursive') 54 git_update_cmd.append('--recursive')
56 subprocess.run(git_sync_cmd, check=True) 55 cli.run(git_sync_cmd, check=True)
57 subprocess.run(git_update_cmd, check=True) 56 cli.run(git_update_cmd, check=True)
58 57
59 else: 58 else:
60 if isinstance(submodules, str): 59 if isinstance(submodules, str):
61 # Update only a single submodule 60 # Update only a single submodule
62 git_sync_cmd.append(submodules) 61 git_sync_cmd.append(submodules)
63 git_update_cmd.append(submodules) 62 git_update_cmd.append(submodules)
64 subprocess.run(git_sync_cmd, check=True) 63 cli.run(git_sync_cmd, check=True)
65 subprocess.run(git_update_cmd, check=True) 64 cli.run(git_update_cmd, check=True)
66 65
67 else: 66 else:
68 # Update submodules in a list 67 # Update submodules in a list
69 for submodule in submodules: 68 for submodule in submodules:
70 subprocess.run(git_sync_cmd + [submodule], check=True) 69 cli.run([*git_sync_cmd, submodule], check=True)
71 subprocess.run(git_update_cmd + [submodule], check=True) 70 cli.run([*git_update_cmd, submodule], check=True)
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
index 741551e5e..d13e42d40 100644
--- a/lib/python/qmk/tests/test_cli_commands.py
+++ b/lib/python/qmk/tests/test_cli_commands.py
@@ -1,15 +1,14 @@
1import platform 1import platform
2from subprocess import DEVNULL
2 3
3from subprocess import STDOUT, PIPE 4from milc import cli
4
5from qmk.commands import run
6 5
7is_windows = 'windows' in platform.platform().lower() 6is_windows = 'windows' in platform.platform().lower()
8 7
9 8
10def check_subcommand(command, *args): 9def check_subcommand(command, *args):
11 cmd = ['bin/qmk', command, *args] 10 cmd = ['bin/qmk', command, *args]
12 result = run(cmd, stdout=PIPE, stderr=STDOUT, universal_newlines=True) 11 result = cli.run(cmd, stdin=DEVNULL, combined_output=True)
13 return result 12 return result
14 13
15 14
@@ -18,7 +17,7 @@ def check_subcommand_stdin(file_to_read, command, *args):
18 """ 17 """
19 with open(file_to_read, encoding='utf-8') as my_file: 18 with open(file_to_read, encoding='utf-8') as my_file:
20 cmd = ['bin/qmk', command, *args] 19 cmd = ['bin/qmk', command, *args]
21 result = run(cmd, stdin=my_file, stdout=PIPE, stderr=STDOUT, universal_newlines=True) 20 result = cli.run(cmd, stdin=my_file, combined_output=True)
22 return result 21 return result
23 22
24 23