-
-
Notifications
You must be signed in to change notification settings - Fork 40k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Align our subprocess usage with current best practices. #12940
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest on MSYS2 fails with:
======================================================================
FAIL: qmk.tests.test_cli_commands.test_c2json
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:/msys64/home/fauxpark/git/qmk_firmware_develop/lib/python/qmk/tests/test_cli_commands.py", line 198, in test_c2json
check_returncode(result)
File "C:/msys64/home/fauxpark/git/qmk_firmware_develop/lib/python/qmk/tests/test_cli_commands.py", line 31, in check_returncode
assert result.returncode in expected
AssertionError
qmk.tests.test_cli_commands.test_c2json ... DEBUG:MILC:Running command: ['C:/msys64/usr/bin/zsh', '-c', 'qmk c2json -kb handwired/pytest/has_template -km default keyboards/handwired/pytest/has_template/keymaps/default/keymap.c']
`C:/msys64/usr/bin/zsh -c qmk c2json -kb handwired/pytest/has_template -km default keyboards/handwired/pytest/has_template/keymaps/default/keymap.c` stdout:
<class 'TypeError'>
ERROR expected string or bytes-like object
Traceback (most recent call last):
File "C:/msys64/mingw64/lib/python3.8/site-packages/milc/milc.py", line 467, in __call__
return self.__call__()
File "C:/msys64/mingw64/lib/python3.8/site-packages/milc/milc.py", line 472, in __call__
return self._entrypoint(self)
File "C:/msys64/home/fauxpark/git/qmk_firmware_develop/lib/python/qmk/cli/c2json.py", line 40, in c2json
keymap_json = qmk.keymap.c2json(cli.args.keyboard, cli.args.keymap, cli.args.filename, use_cpp=cli.args.no_cpp)
File "C:/msys64/home/fauxpark/git/qmk_firmware_develop/lib/python/qmk/keymap.py", line 545, in c2json
keymap_json = parse_keymap_c(keymap_file, use_cpp)
File "C:/msys64/home/fauxpark/git/qmk_firmware_develop/lib/python/qmk/keymap.py", line 519, in parse_keymap_c
keymap_file = _c_preprocess(keymap_file)
File "C:/msys64/home/fauxpark/git/qmk_firmware_develop/lib/python/qmk/keymap.py", line 374, in _c_preprocess
pre_processed_keymap = cli.run(cmd, stdin=stdin)
File "C:/msys64/mingw64/lib/python3.8/site-packages/milc/milc.py", line 125, in run
safecmd = ' '.join(safecmd)
File "C:/msys64/mingw64/lib/python3.8/shlex.py", line 325, in quote
if _find_unsafe(s) is None:
TypeError: expected string or bytes-like object
returncode: 255
FAIL
(I'm not sure whether it's related, though)
Co-authored-by: Ryan <fauxpark@gmail.com>
@@ -371,7 +370,9 @@ def _c_preprocess(path, stdin=None): | |||
Returns: | |||
the stdout of the pre-processor | |||
""" | |||
pre_processed_keymap = qmk.commands.run(['cpp', path] if path else ['cpp'], stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | |||
cmd = ['cpp', str(path)] if path else ['cpp'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If path
is always an object of type Path
then I think this should use .as_posix()
instead, otherwise LGTM 👍
* 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>
* 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>
* 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>
* 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>
Description
This switches most of our subprocess usage to MILC's
cli.run()
. There are still a couple places that use subprocess.run which I didn't want to change just now.I added
stdin=DEVNULL
to most commands because this fixes a bug on windows where input is no longer accepted after a subprocess is run.Types of Changes
Checklist