14
14
#
15
15
16
16
from __future__ import print_function
17
- import sys
18
- import re
17
+
18
+ import argparse
19
19
import os
20
+ import re
20
21
import subprocess
21
- import argparse
22
+ import sys
22
23
import tempfile
23
24
24
-
25
25
EXPECTED_VERSION = "8.0.1"
26
26
VERSION_REGEX = re .compile (r"clang-format version ([0-9.]+)" )
27
- # NOTE: populate this list with more top-level dirs as we add more of them to the rmm repo
28
- DEFAULT_DIRS = ["src" ,
29
- "include" ,
30
- "tests" ,
31
- "benchmarks" ]
27
+ # NOTE: populate this list with more top-level dirs as we add more of them
28
+ # to the rmm repo
29
+ DEFAULT_DIRS = ["src" , "include" , "tests" , "benchmarks" ]
32
30
33
31
34
32
def parse_args ():
35
33
argparser = argparse .ArgumentParser ("Runs clang-format on a project" )
36
- argparser .add_argument ("-dstdir" , type = str , default = None ,
37
- help = "Directory to store the temporary outputs of"
38
- " clang-format. If nothing is passed for this, then"
39
- " a temporary dir will be created using `mkdtemp`" )
40
- argparser .add_argument ("-exe" , type = str , default = "clang-format" ,
41
- help = "Path to clang-format exe" )
42
- argparser .add_argument ("-inplace" , default = False , action = "store_true" ,
43
- help = "Replace the source files itself." )
44
- argparser .add_argument ("-regex" , type = str ,
45
- default = r"[.](cu|cuh|h|hpp|cpp)$" ,
46
- help = "Regex string to filter in sources" )
47
- argparser .add_argument ("-ignore" , type = str , default = r"cannylab/bh[.]cu$" ,
48
- help = "Regex used to ignore files from matched list" )
49
- argparser .add_argument ("-v" , dest = "verbose" , action = "store_true" ,
50
- help = "Print verbose messages" )
51
- argparser .add_argument ("dirs" , type = str , nargs = "*" ,
52
- help = "List of dirs where to find sources" )
34
+ argparser .add_argument (
35
+ "-dstdir" ,
36
+ type = str ,
37
+ default = None ,
38
+ help = "Directory to store the temporary outputs of"
39
+ " clang-format. If nothing is passed for this, then"
40
+ " a temporary dir will be created using `mkdtemp`" ,
41
+ )
42
+ argparser .add_argument (
43
+ "-exe" ,
44
+ type = str ,
45
+ default = "clang-format" ,
46
+ help = "Path to clang-format exe" ,
47
+ )
48
+ argparser .add_argument (
49
+ "-inplace" ,
50
+ default = False ,
51
+ action = "store_true" ,
52
+ help = "Replace the source files itself." ,
53
+ )
54
+ argparser .add_argument (
55
+ "-regex" ,
56
+ type = str ,
57
+ default = r"[.](cu|cuh|h|hpp|cpp)$" ,
58
+ help = "Regex string to filter in sources" ,
59
+ )
60
+ argparser .add_argument (
61
+ "-ignore" ,
62
+ type = str ,
63
+ default = r"cannylab/bh[.]cu$" ,
64
+ help = "Regex used to ignore files from matched list" ,
65
+ )
66
+ argparser .add_argument (
67
+ "-v" ,
68
+ dest = "verbose" ,
69
+ action = "store_true" ,
70
+ help = "Print verbose messages" ,
71
+ )
72
+ argparser .add_argument (
73
+ "dirs" , type = str , nargs = "*" , help = "List of dirs where to find sources"
74
+ )
53
75
args = argparser .parse_args ()
54
76
args .regex_compiled = re .compile (args .regex )
55
77
args .ignore_compiled = re .compile (args .ignore )
@@ -62,8 +84,10 @@ def parse_args():
62
84
raise Exception ("Failed to figure out clang-format version!" )
63
85
version = version .group (1 )
64
86
if version != EXPECTED_VERSION :
65
- raise Exception ("clang-format exe must be v%s found '%s'" % \
66
- (EXPECTED_VERSION , version ))
87
+ raise Exception (
88
+ "clang-format exe must be v%s found '%s'"
89
+ % (EXPECTED_VERSION , version )
90
+ )
67
91
if len (args .dirs ) == 0 :
68
92
args .dirs = DEFAULT_DIRS
69
93
return args
@@ -108,8 +132,10 @@ def run_clang_format(src, dst, exe, verbose):
108
132
if verbose :
109
133
print ("%s passed" % os .path .basename (src ))
110
134
except subprocess .CalledProcessError :
111
- print ("%s failed! 'diff %s %s' will show formatting violations!" % \
112
- (os .path .basename (src ), src , dst ))
135
+ print (
136
+ "%s failed! 'diff %s %s' will show formatting violations!"
137
+ % (os .path .basename (src ), src , dst )
138
+ )
113
139
return False
114
140
return True
115
141
@@ -120,8 +146,13 @@ def main():
120
146
if not os .path .exists (".git" ):
121
147
print ("Error!! This needs to always be run from the root of repo" )
122
148
sys .exit (- 1 )
123
- all_files = list_all_src_files (args .regex_compiled , args .ignore_compiled ,
124
- args .dirs , args .dstdir , args .inplace )
149
+ all_files = list_all_src_files (
150
+ args .regex_compiled ,
151
+ args .ignore_compiled ,
152
+ args .dirs ,
153
+ args .dstdir ,
154
+ args .inplace ,
155
+ )
125
156
# actual format checker
126
157
status = True
127
158
for src , dst in all_files :
@@ -132,8 +163,10 @@ def main():
132
163
print (" 1. Look at formatting differences above and fix them manually" )
133
164
print (" 2. Or run the below command to bulk-fix all these at once" )
134
165
print ("Bulk-fix command: " )
135
- print (" python scripts/run-clang-format.py %s -inplace" % \
136
- " " .join (sys .argv [1 :]))
166
+ print (
167
+ " python scripts/run-clang-format.py %s -inplace"
168
+ % " " .join (sys .argv [1 :])
169
+ )
137
170
sys .exit (- 1 )
138
171
return
139
172
0 commit comments