diff options
Diffstat (limited to 'lib/python/qmk/cli/cformat.py')
| -rw-r--r-- | lib/python/qmk/cli/cformat.py | 10 |
1 files changed, 5 insertions, 5 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 | """ |
| 3 | import subprocess | ||
| 4 | from os import path | 3 | from os import path |
| 5 | from shutil import which | 4 | from shutil import which |
| 5 | from subprocess import CalledProcessError, DEVNULL, Popen, PIPE | ||
| 6 | 6 | ||
| 7 | from argcomplete.completers import FilesCompleter | 7 | from argcomplete.completers import FilesCompleter |
| 8 | from milc import cli | 8 | from 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) |
