@@ -41,7 +41,8 @@ def filter_ignored_files(names):
41
41
proc = subprocess .run (
42
42
["git" , "check-ignore" , "--no-index" , "-n" , "-v" , "--stdin" ],
43
43
input = encoded_names ,
44
- stdout = subprocess .PIPE )
44
+ stdout = subprocess .PIPE ,
45
+ )
45
46
if proc .returncode == 128 :
46
47
raise subprocess .CalledProcessError
47
48
@@ -51,7 +52,7 @@ def filter_ignored_files(names):
51
52
# wraps names in quotes on Windows, and outputs "\n" line separators on all
52
53
# platforms.
53
54
return [
54
- name [2 :].lstrip ().strip (" \" " ).replace ("\\ \\ " , "\\ " )
55
+ name [2 :].lstrip ().strip ('"' ).replace ("\\ \\ " , "\\ " )
55
56
for name in output_list
56
57
if name [0 :2 ] == "::"
57
58
]
@@ -260,33 +261,33 @@ def run_batch(task_pipeline, args, file_batches):
260
261
def main ():
261
262
# Parse command-line arguments
262
263
parser = argparse .ArgumentParser (
263
- description =
264
- "Runs all formatting tasks on the code base. This should be invoked from a directory within the project."
264
+ description = "Runs all formatting tasks on the code base. This should be invoked from a directory within the project."
265
265
)
266
266
parser .add_argument (
267
267
"-v" ,
268
268
dest = "verbose1" ,
269
269
action = "store_true" ,
270
- help = "verbosity level 1 (prints names of processed files)" )
270
+ help = "verbosity level 1 (prints names of processed files)" ,
271
+ )
271
272
parser .add_argument (
272
273
"-vv" ,
273
274
dest = "verbose2" ,
274
275
action = "store_true" ,
275
- help =
276
- "verbosity level 2 (prints names of processed files and tasks run on them)"
276
+ help = "verbosity level 2 (prints names of processed files and tasks run on them)" ,
277
277
)
278
278
list_files_group = parser .add_mutually_exclusive_group ()
279
279
list_files_group .add_argument (
280
280
"-list-all-files" ,
281
281
dest = "list_all_files" ,
282
282
action = "store_true" ,
283
- help = "list files to be processed instead of processing them" )
283
+ help = "list files to be processed instead of processing them" ,
284
+ )
284
285
list_files_group .add_argument (
285
286
"-list-changed-files" ,
286
287
dest = "list_changed_files" ,
287
288
action = "store_true" ,
288
- help =
289
- "same as list-all-files, but list only files changed from main branch" )
289
+ help = "same as list-all-files, but list only files changed from main branch" ,
290
+ )
290
291
# mp.Pool() uses WaitForMultipleObjects() to wait for subprocess completion
291
292
# on Windows. WaitForMultipleObjects() cannot wait on more then 64 events at
292
293
# once, and mp uses a few internal events. Therefore, the maximum number of
@@ -297,51 +298,49 @@ def main():
297
298
dest = "jobs" ,
298
299
type = int ,
299
300
default = cpu_count ,
300
- help = "number of jobs to run (default is number of cores)" )
301
+ help = "number of jobs to run (default is number of cores)" ,
302
+ )
301
303
parser .add_argument (
302
304
"-clang" ,
303
305
dest = "clang_version" ,
304
306
type = str ,
305
307
default = "" ,
306
- help =
307
- "version suffix for clang-format (invokes \" clang-format-CLANG_VERSION\" or \" clang-format\" if no suffix provided)"
308
+ help = 'version suffix for clang-format (invokes "clang-format-CLANG_VERSION" or "clang-format" if no suffix provided)' ,
308
309
)
309
310
tidy_group = parser .add_mutually_exclusive_group ()
310
311
tidy_group .add_argument (
311
312
"-tidy-changed" ,
312
313
dest = "tidy_changed" ,
313
314
action = "store_true" ,
314
- help =
315
- "also runs clang-tidy-CLANG_VERSION on changed files; this requires a compile_commands.json file"
315
+ help = "also runs clang-tidy-CLANG_VERSION on changed files; this requires a compile_commands.json file" ,
316
316
)
317
317
tidy_group .add_argument (
318
318
"-tidy-all" ,
319
319
dest = "tidy_all" ,
320
320
action = "store_true" ,
321
- help =
322
- "also runs clang-tidy-CLANG_VERSION on all files (this takes a while); this requires a compile_commands.json file"
321
+ help = "also runs clang-tidy-CLANG_VERSION on all files (this takes a while); this requires a compile_commands.json file" ,
323
322
)
324
323
parser .add_argument (
325
324
"-compile-commands" ,
326
325
dest = "compile_commands" ,
327
326
type = str ,
328
327
default = "" ,
329
- help =
330
- "path to directory containing compile_commands.json; if unset will search in parent paths"
328
+ help = "path to directory containing compile_commands.json; if unset will search in parent paths" ,
331
329
)
332
330
parser .add_argument (
333
331
"-f" ,
334
332
dest = "file" ,
335
333
type = str ,
336
334
default = "" ,
337
335
nargs = "+" ,
338
- help =
339
- "file or directory names (can be path relative to python invocation directory or absolute path)"
336
+ help = "file or directory names (can be path relative to python invocation directory or absolute path)" ,
337
+ )
338
+ parser .add_argument (
339
+ "-no-format" ,
340
+ dest = "no_format" ,
341
+ action = "store_true" ,
342
+ help = "disable formatting steps, only run linting" ,
340
343
)
341
- parser .add_argument ("-no-format" ,
342
- dest = "no_format" ,
343
- action = "store_true" ,
344
- help = "disable formatting steps, only run linting" )
345
344
args = parser .parse_args ()
346
345
347
346
# tidy requires compile_commands.json
@@ -350,7 +349,8 @@ def main():
350
349
if not os .path .exists (ccloc ):
351
350
print (
352
351
f"error: clang-tidy: { ccloc } not found (try -compile-commands)" ,
353
- file = sys .stderr )
352
+ file = sys .stderr ,
353
+ )
354
354
sys .exit (1 )
355
355
356
356
# All discovered files are relative to Git repo root directory, so find the
@@ -373,9 +373,7 @@ def main():
373
373
os .remove (f )
374
374
375
375
# Recursively create list of files in given directory
376
- files = [
377
- os .path .join (dp , f ) for dp , dn , fn in os .walk (root_path ) for f in fn
378
- ]
376
+ files = [os .path .join (dp , f ) for dp , dn , fn in os .walk (root_path ) for f in fn ]
379
377
380
378
if not files :
381
379
print ("Error: no files found to format" , file = sys .stderr )
@@ -385,11 +383,9 @@ def main():
385
383
for name in args .file :
386
384
# If a directory was specified, recursively expand it
387
385
if os .path .isdir (name ):
388
- files .extend ([
389
- os .path .join (dp , f )
390
- for dp , dn , fn in os .walk (name )
391
- for f in fn
392
- ])
386
+ files .extend (
387
+ [os .path .join (dp , f ) for dp , dn , fn in os .walk (name ) for f in fn ]
388
+ )
393
389
else :
394
390
files .append (name )
395
391
@@ -412,8 +408,9 @@ def main():
412
408
branch_options = ["master" , "main" ]
413
409
main_branch = ""
414
410
for branch in branch_options :
415
- proc = subprocess .run (["git" , "rev-parse" , "-q" , "--verify" , branch ],
416
- stdout = subprocess .DEVNULL )
411
+ proc = subprocess .run (
412
+ ["git" , "rev-parse" , "-q" , "--verify" , branch ], stdout = subprocess .DEVNULL
413
+ )
417
414
if proc .returncode == 0 :
418
415
main_branch = branch
419
416
break
@@ -426,10 +423,9 @@ def main():
426
423
427
424
# Create list of all changed files
428
425
output_list = subprocess .check_output (
429
- ["git" , "diff" , "--name-only" , main_branch ], encoding = "ascii" ).split ()
430
- changed_file_list = [
431
- root_path + os .sep + line .strip () for line in output_list
432
- ]
426
+ ["git" , "diff" , "--name-only" , main_branch ], encoding = "ascii"
427
+ ).split ()
428
+ changed_file_list = [root_path + os .sep + line .strip () for line in output_list ]
433
429
434
430
# Don't run tasks on modifiable or generated files
435
431
work = []
@@ -461,9 +457,7 @@ def main():
461
457
462
458
# Prepare file batches for batch tasks
463
459
chunksize = math .ceil (len (files ) / args .jobs )
464
- file_batches = [
465
- files [i :i + chunksize ] for i in range (0 , len (files ), chunksize )
466
- ]
460
+ file_batches = [files [i : i + chunksize ] for i in range (0 , len (files ), chunksize )]
467
461
468
462
if args .no_format :
469
463
# Only run Lint
0 commit comments