1
0
Fork 0

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>
This commit is contained in:
Zach White 2021-05-19 15:24:46 -07:00 committed by GitHub
parent a9aec546c8
commit db1eacdaac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 70 additions and 78 deletions

View file

@ -2,11 +2,9 @@
"""
import json
import os
import platform
import subprocess
import shlex
import shutil
from pathlib import Path
from subprocess import DEVNULL
from time import strftime
from milc import cli
@ -94,7 +92,7 @@ def get_git_version(repo_dir='.', check_dir='.'):
git_describe_cmd = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags']
if Path(check_dir).exists():
git_describe = cli.run(git_describe_cmd, cwd=repo_dir)
git_describe = cli.run(git_describe_cmd, stdin=DEVNULL, cwd=repo_dir)
if git_describe.returncode == 0:
return git_describe.stdout.strip()
@ -224,20 +222,3 @@ def parse_configurator_json(configurator_file):
user_keymap['layout'] = aliases[orig_keyboard]['layouts'][user_keymap['layout']]
return user_keymap
def run(command, *args, **kwargs):
"""Run a command with subprocess.run
"""
platform_id = platform.platform().lower()
if isinstance(command, str):
raise TypeError('`command` must be a non-text sequence such as list or tuple.')
if 'windows' in platform_id:
safecmd = map(str, command)
safecmd = map(shlex.quote, safecmd)
safecmd = ' '.join(safecmd)
command = [os.environ.get('SHELL', '/usr/bin/bash'), '-c', safecmd]
return subprocess.run(command, *args, **kwargs)