@@ -17,14 +17,14 @@ def run_format(args, queue, lock, failed_files):
17
17
"""Takes filenames out of queue and runs clang-format on them."""
18
18
while True :
19
19
path = queue .get ()
20
- invocation = [' clang-format-11' ]
20
+ invocation = [" clang-format-11" ]
21
21
if args .inplace :
22
- invocation .append ('-i' )
22
+ invocation .append ("-i" )
23
23
else :
24
- invocation .extend ([' --dry-run' , ' -Werror' ])
24
+ invocation .extend ([" --dry-run" , " -Werror" ])
25
25
invocation .append (path )
26
26
27
- proc = subprocess .run (invocation , capture_output = True , encoding = ' utf-8' )
27
+ proc = subprocess .run (invocation , capture_output = True , encoding = " utf-8" )
28
28
if proc .returncode != 0 :
29
29
with lock :
30
30
print_error_for_file (path , proc .stderr )
@@ -33,45 +33,54 @@ def run_format(args, queue, lock, failed_files):
33
33
34
34
35
35
def progress_bar_show (value ):
36
- return value if value is not None else ''
36
+ return value if value is not None else ""
37
37
38
38
39
39
def main ():
40
40
colorama .init ()
41
41
42
42
parser = argparse .ArgumentParser ()
43
- parser .add_argument ('-j' , '--jobs' , type = int ,
44
- default = multiprocessing .cpu_count (),
45
- help = 'number of format instances to be run in parallel.' )
46
- parser .add_argument ('files' , nargs = '*' , default = [],
47
- help = 'files to be processed (regex on path)' )
48
- parser .add_argument ('-i' , '--inplace' , action = 'store_true' ,
49
- help = 'reformat files in-place' )
50
- parser .add_argument ('-c' , '--changed' , action = 'store_true' ,
51
- help = 'only run on changed files' )
43
+ parser .add_argument (
44
+ "-j" ,
45
+ "--jobs" ,
46
+ type = int ,
47
+ default = multiprocessing .cpu_count (),
48
+ help = "number of format instances to be run in parallel." ,
49
+ )
50
+ parser .add_argument (
51
+ "files" , nargs = "*" , default = [], help = "files to be processed (regex on path)"
52
+ )
53
+ parser .add_argument (
54
+ "-i" , "--inplace" , action = "store_true" , help = "reformat files in-place"
55
+ )
56
+ parser .add_argument (
57
+ "-c" , "--changed" , action = "store_true" , help = "only run on changed files"
58
+ )
52
59
args = parser .parse_args ()
53
60
54
61
try :
55
- get_output (' clang-format-11' , ' -version' )
62
+ get_output (" clang-format-11" , " -version" )
56
63
except :
57
- print ("""
64
+ print (
65
+ """
58
66
Oops. It looks like clang-format is not installed.
59
67
60
68
Please check you can run "clang-format-11 -version" in your terminal and install
61
69
clang-format (v11) if necessary.
62
70
63
71
Note you can also upload your code as a pull request on GitHub and see the CI check
64
72
output to apply clang-format.
65
- """ )
73
+ """
74
+ )
66
75
return 1
67
76
68
77
files = []
69
- for path in git_ls_files ([' *.cpp' , ' *.h' , ' *.tcc' ]):
78
+ for path in git_ls_files ([" *.cpp" , " *.h" , " *.tcc" ]):
70
79
files .append (os .path .relpath (path , os .getcwd ()))
71
80
72
81
if args .files :
73
82
# Match against files specified on command-line
74
- file_name_re = re .compile ('|' .join (args .files ))
83
+ file_name_re = re .compile ("|" .join (args .files ))
75
84
files = [p for p in files if file_name_re .search (p )]
76
85
77
86
if args .changed :
@@ -84,14 +93,16 @@ def main():
84
93
task_queue = queue .Queue (args .jobs )
85
94
lock = threading .Lock ()
86
95
for _ in range (args .jobs ):
87
- t = threading .Thread (target = run_format ,
88
- args = (args , task_queue , lock , failed_files ))
96
+ t = threading .Thread (
97
+ target = run_format , args = (args , task_queue , lock , failed_files )
98
+ )
89
99
t .daemon = True
90
100
t .start ()
91
101
92
102
# Fill the queue with files.
93
- with click .progressbar (files , width = 30 , file = sys .stderr ,
94
- item_show_func = progress_bar_show ) as bar :
103
+ with click .progressbar (
104
+ files , width = 30 , file = sys .stderr , item_show_func = progress_bar_show
105
+ ) as bar :
95
106
for name in bar :
96
107
task_queue .put (name )
97
108
@@ -100,11 +111,11 @@ def main():
100
111
101
112
except KeyboardInterrupt :
102
113
print ()
103
- print (' Ctrl-C detected, goodbye.' )
114
+ print (" Ctrl-C detected, goodbye." )
104
115
os .kill (0 , 9 )
105
116
106
117
sys .exit (len (failed_files ))
107
118
108
119
109
- if __name__ == ' __main__' :
120
+ if __name__ == " __main__" :
110
121
main ()
0 commit comments