diff options
author | Joel Challis <git@zvecr.com> | 2021-11-23 00:23:23 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 00:23:23 +0000 |
commit | dbc7b535178020063f80aaaabac3ca8ff9f6e8bb (patch) | |
tree | 56805386c888d9413e9d2b4ed41db5c16fdb7cd1 /lib/python/qmk/cli/format | |
parent | 97a32eedf1cebc1fdd771d0c67ee8320c06e8d99 (diff) | |
download | qmk_firmware-dbc7b535178020063f80aaaabac3ca8ff9f6e8bb.tar.gz qmk_firmware-dbc7b535178020063f80aaaabac3ca8ff9f6e8bb.zip |
qmk format-python - filter for Python files (#15271)
* qmk format-python filter all files
* filter changed files too
Diffstat (limited to 'lib/python/qmk/cli/format')
-rwxr-xr-x | lib/python/qmk/cli/format/python.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/python/qmk/cli/format/python.py b/lib/python/qmk/cli/format/python.py index 95868d18a0..47b5c45fd5 100755 --- a/lib/python/qmk/cli/format/python.py +++ b/lib/python/qmk/cli/format/python.py @@ -25,9 +25,8 @@ def yapf_run(files): def filter_files(files): """Yield only files to be formatted and skip the rest """ - for file in files: - if file and file.name.split('.')[-1] in py_file_suffixes: + if file and normpath(file).name.split('.')[-1] in py_file_suffixes: yield file else: cli.log.debug('Skipping file %s', file) @@ -53,12 +52,14 @@ def format_python(cli): cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(map(str, files))) elif cli.args.all_files: - files = py_dirs + git_ls_cmd = ['git', 'ls-files', *py_dirs] + git_ls = cli.run(git_ls_cmd, stdin=DEVNULL) + files = list(filter_files(git_ls.stdout.split('\n'))) else: git_diff_cmd = ['git', 'diff', '--name-only', cli.args.base_branch, *py_dirs] git_diff = cli.run(git_diff_cmd, stdin=DEVNULL) - files = list(filter(None, git_diff.stdout.split('\n'))) + files = list(filter_files(git_diff.stdout.split('\n'))) # Sanity check if not files: |