diff options
author | Joel Challis <git@zvecr.com> | 2022-01-03 21:54:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-03 21:54:46 +0000 |
commit | aea71554234cce71f9f9d4087253e53d2729f9a7 (patch) | |
tree | aa4a529fc95f46670d76001163b4165d6108bec5 /lib/python | |
parent | a88dc08643af76e19eff72dbd9b2a0cefea3f23f (diff) | |
download | qmk_firmware-aea71554234cce71f9f9d4087253e53d2729f9a7.tar.gz qmk_firmware-aea71554234cce71f9f9d4087253e53d2729f9a7.zip |
Fix "No C files in filelist: None" (#15560)
* Fix "No C files in filelist: None"
* Align other commands
* force absolute paths
Diffstat (limited to 'lib/python')
-rw-r--r-- | lib/python/qmk/cli/format/c.py | 22 | ||||
-rwxr-xr-x | lib/python/qmk/cli/format/python.py | 3 |
2 files changed, 14 insertions, 11 deletions
diff --git a/lib/python/qmk/cli/format/c.py b/lib/python/qmk/cli/format/c.py index 568684ed5..fe2f97da9 100644 --- a/lib/python/qmk/cli/format/c.py +++ b/lib/python/qmk/cli/format/c.py | |||
@@ -1,6 +1,5 @@ | |||
1 | """Format C code according to QMK's style. | 1 | """Format C code according to QMK's style. |
2 | """ | 2 | """ |
3 | from os import path | ||
4 | from shutil import which | 3 | from shutil import which |
5 | from subprocess import CalledProcessError, DEVNULL, Popen, PIPE | 4 | from subprocess import CalledProcessError, DEVNULL, Popen, PIPE |
6 | 5 | ||
@@ -15,6 +14,12 @@ core_dirs = ('drivers', 'quantum', 'tests', 'tmk_core', 'platforms') | |||
15 | ignored = ('tmk_core/protocol/usb_hid', 'platforms/chibios/boards') | 14 | ignored = ('tmk_core/protocol/usb_hid', 'platforms/chibios/boards') |
16 | 15 | ||
17 | 16 | ||
17 | def is_relative_to(file, other): | ||
18 | """Provide similar behavior to PurePath.is_relative_to in Python > 3.9 | ||
19 | """ | ||
20 | return str(normpath(file).resolve()).startswith(str(normpath(other).resolve())) | ||
21 | |||
22 | |||
18 | def find_clang_format(): | 23 | def find_clang_format(): |
19 | """Returns the path to clang-format. | 24 | """Returns the path to clang-format. |
20 | """ | 25 | """ |
@@ -68,18 +73,19 @@ def cformat_run(files): | |||
68 | def filter_files(files, core_only=False): | 73 | def filter_files(files, core_only=False): |
69 | """Yield only files to be formatted and skip the rest | 74 | """Yield only files to be formatted and skip the rest |
70 | """ | 75 | """ |
76 | files = list(map(normpath, filter(None, files))) | ||
71 | if core_only: | 77 | if core_only: |
72 | # Filter non-core files | 78 | # Filter non-core files |
73 | for index, file in enumerate(files): | 79 | for index, file in enumerate(files): |
74 | # The following statement checks each file to see if the file path is | 80 | # The following statement checks each file to see if the file path is |
75 | # - in the core directories | 81 | # - in the core directories |
76 | # - not in the ignored directories | 82 | # - not in the ignored directories |
77 | if not any(str(file).startswith(i) for i in core_dirs) or any(str(file).startswith(i) for i in ignored): | 83 | if not any(is_relative_to(file, i) for i in core_dirs) or any(is_relative_to(file, i) for i in ignored): |
78 | files[index] = None | 84 | del files[index] |
79 | cli.log.debug("Skipping non-core file %s, as '--core-only' is used.", file) | 85 | cli.log.debug("Skipping non-core file %s, as '--core-only' is used.", file) |
80 | 86 | ||
81 | for file in files: | 87 | for file in files: |
82 | if file and file.name.split('.')[-1] in c_file_suffixes: | 88 | if file.suffix[1:] in c_file_suffixes: |
83 | yield file | 89 | yield file |
84 | else: | 90 | else: |
85 | cli.log.debug('Skipping file %s', file) | 91 | cli.log.debug('Skipping file %s', file) |
@@ -118,12 +124,8 @@ def format_c(cli): | |||
118 | print(git_diff.stderr) | 124 | print(git_diff.stderr) |
119 | return git_diff.returncode | 125 | return git_diff.returncode |
120 | 126 | ||
121 | files = [] | 127 | changed_files = git_diff.stdout.strip().split('\n') |
122 | 128 | files = list(filter_files(changed_files, True)) | |
123 | for file in git_diff.stdout.strip().split('\n'): | ||
124 | if not any([file.startswith(ignore) for ignore in ignored]): | ||
125 | if path.exists(file) and file.split('.')[-1] in c_file_suffixes: | ||
126 | files.append(file) | ||
127 | 129 | ||
128 | # Sanity check | 130 | # Sanity check |
129 | if not files: | 131 | if not files: |
diff --git a/lib/python/qmk/cli/format/python.py b/lib/python/qmk/cli/format/python.py index 47b5c45fd..008622cac 100755 --- a/lib/python/qmk/cli/format/python.py +++ b/lib/python/qmk/cli/format/python.py | |||
@@ -25,8 +25,9 @@ def yapf_run(files): | |||
25 | def filter_files(files): | 25 | def filter_files(files): |
26 | """Yield only files to be formatted and skip the rest | 26 | """Yield only files to be formatted and skip the rest |
27 | """ | 27 | """ |
28 | files = list(map(normpath, filter(None, files))) | ||
28 | for file in files: | 29 | for file in files: |
29 | if file and normpath(file).name.split('.')[-1] in py_file_suffixes: | 30 | if file.suffix[1:] in py_file_suffixes: |
30 | yield file | 31 | yield file |
31 | else: | 32 | else: |
32 | cli.log.debug('Skipping file %s', file) | 33 | cli.log.debug('Skipping file %s', file) |