Skip to content

Commit 518a7ca

Browse files
Panquesito7github-actions[bot]
and
github-actions[bot]
authored
chore: add the linter to a separate Python script (#1272)
* updating DIRECTORY.md * chore: add the linter to a separate Python script --------- Co-authored-by: github-actions[bot] <[email protected]>
1 parent 1bbbac6 commit 518a7ca

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

.github/workflows/awesome_workflow.yml

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

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.out
44
.vscode/
55
build/
6+
git_diff.txt

scripts/file_linter.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
subprocess.run(["clang-tidy", "-p=build", "--fix", *cpp_files, "--"],
16+
check=True, text=True, stderr=subprocess.STDOUT)
17+
subprocess.run(["clang-format", "-i", *cpp_files],
18+
check=True, text=True, stderr=subprocess.STDOUT)
19+
20+
upper_files = [file for file in cpp_files if file != file.lower()]
21+
if upper_files:
22+
print(f"{len(upper_files)} files contain uppercase characters:")
23+
print("\n".join(upper_files) + "\n")
24+
25+
space_files = [file for file in cpp_files if " " in file or "-" in file]
26+
if space_files:
27+
print(f"{len(space_files)} files contain space or dash characters:")
28+
print("\n".join(space_files) + "\n")
29+
30+
nodir_files = [file for file in cpp_files if file.count(os.sep) != 1 and "project_euler" not in file and "data_structure" not in file]
31+
if len(nodir_files) > 1:
32+
nodir_file_bad_files = len(nodir_files) - 1
33+
print(f"{len(nodir_files)} files are not in one and only one directory:")
34+
print("\n".join(nodir_files) + "\n")
35+
else:
36+
nodir_file_bad_files = 0
37+
bad_files = nodir_file_bad_files + len(upper_files + space_files)
38+
39+
if bad_files:
40+
sys.exit(bad_files)

0 commit comments

Comments
 (0)