aboutsummaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2022-01-03 21:54:46 +0000
committerGitHub <noreply@github.com>2022-01-03 21:54:46 +0000
commitaea71554234cce71f9f9d4087253e53d2729f9a7 (patch)
treeaa4a529fc95f46670d76001163b4165d6108bec5 /lib/python
parenta88dc08643af76e19eff72dbd9b2a0cefea3f23f (diff)
downloadqmk_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.py22
-rwxr-xr-xlib/python/qmk/cli/format/python.py3
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"""
3from os import path
4from shutil import which 3from shutil import which
5from subprocess import CalledProcessError, DEVNULL, Popen, PIPE 4from subprocess import CalledProcessError, DEVNULL, Popen, PIPE
6 5
@@ -15,6 +14,12 @@ core_dirs = ('drivers', 'quantum', 'tests', 'tmk_core', 'platforms')
15ignored = ('tmk_core/protocol/usb_hid', 'platforms/chibios/boards') 14ignored = ('tmk_core/protocol/usb_hid', 'platforms/chibios/boards')
16 15
17 16
17def 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
18def find_clang_format(): 23def 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):
68def filter_files(files, core_only=False): 73def 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):
25def filter_files(files): 25def 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)