Skip to content

Commit f4d1aa1

Browse files
authored
chore: add the linter to a separate Python script (#2500)
1 parent 32db99c commit f4d1aa1

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
lines changed

Diff for: .github/workflows/awesome_workflow.yml

+2-41
Original file line numberDiff line numberDiff line change
@@ -38,47 +38,8 @@ jobs:
3838
# be able to catch any errors for other platforms.
3939
run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
4040
- name: Lint modified files
41-
shell: python
42-
run: |
43-
import os
44-
import subprocess
45-
import sys
46-
47-
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
48-
with open("git_diff.txt") as in_file:
49-
modified_files = sorted(in_file.read().splitlines())
50-
print("{} files were modified.".format(len(modified_files)))
51-
52-
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
53-
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
54-
print(f"{len(cpp_files)} C++ files were modified.")
55-
if not cpp_files:
56-
sys.exit(0)
57-
58-
subprocess.run(["clang-tidy", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"],
59-
check=True, text=True, stderr=subprocess.STDOUT)
60-
61-
subprocess.run(["clang-format", "-i", "-style=file", *cpp_files],
62-
check=True, text=True, stderr=subprocess.STDOUT)
63-
64-
upper_files = [file for file in cpp_files if file != file.lower()]
65-
if upper_files:
66-
print(f"{len(upper_files)} files contain uppercase characters:")
67-
print("\n".join(upper_files) + "\n")
68-
69-
space_files = [file for file in cpp_files if " " in file or "-" in file]
70-
if space_files:
71-
print(f"{len(space_files)} files contain space or dash characters:")
72-
print("\n".join(space_files) + "\n")
73-
74-
nodir_files = [file for file in cpp_files if file.count(os.sep) != 1]
75-
if nodir_files:
76-
print(f"{len(nodir_files)} files are not in one and only one directory:")
77-
print("\n".join(nodir_files) + "\n")
78-
79-
bad_files = len(upper_files + space_files + nodir_files)
80-
if bad_files:
81-
sys.exit(bad_files)
41+
shell: bash
42+
run: python3 scripts/file_linter.py
8243
- name: Commit and push changes
8344
run: |
8445
git diff DIRECTORY.md

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ a.out
3535
*.app
3636

3737
build/
38+
git_diff.txt

Diff for: scripts/file_linter.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
6+
with open("git_diff.txt") as in_file:
7+
modified_files = sorted(in_file.read().splitlines())
8+
print("{} files were modified.".format(len(modified_files)))
9+
10+
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
11+
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
12+
print(f"{len(cpp_files)} C++ files were modified.")
13+
if not cpp_files:
14+
sys.exit(0)
15+
16+
subprocess.run(["clang-tidy", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"],
17+
check=True, text=True, stderr=subprocess.STDOUT)
18+
19+
subprocess.run(["clang-format", "-i", "-style=file", *cpp_files],
20+
check=True, text=True, stderr=subprocess.STDOUT)
21+
22+
upper_files = [file for file in cpp_files if file != file.lower()]
23+
if upper_files:
24+
print(f"{len(upper_files)} files contain uppercase characters:")
25+
print("\n".join(upper_files) + "\n")
26+
27+
space_files = [file for file in cpp_files if " " in file or "-" in file]
28+
if space_files:
29+
print(f"{len(space_files)} files contain space or dash characters:")
30+
print("\n".join(space_files) + "\n")
31+
32+
nodir_files = [file for file in cpp_files if file.count(os.sep) != 1]
33+
if nodir_files:
34+
print(f"{len(nodir_files)} files are not in one and only one directory:")
35+
print("\n".join(nodir_files) + "\n")
36+
37+
bad_files = len(upper_files + space_files + nodir_files)
38+
if bad_files:
39+
sys.exit(bad_files)

0 commit comments

Comments
 (0)