16
16
import sys
17
17
import token
18
18
import tokenize
19
- from typing import IO , Callable , FrozenSet , Iterable , List , Set , Tuple
19
+ from typing import IO , Callable , FrozenSet , Iterable , List , Sequence , Set , Tuple
20
20
21
21
PRIVATE_IMPORTS_TO_IGNORE : Set [str ] = {
22
22
"_extension_array_shared_docs" ,
@@ -403,7 +403,7 @@ def has_wrong_whitespace(first_line: str, second_line: str) -> bool:
403
403
404
404
def main (
405
405
function : Callable [[IO [str ]], Iterable [Tuple [int , str ]]],
406
- source_path : str ,
406
+ source_paths : Sequence [ str ] ,
407
407
output_format : str ,
408
408
file_extensions_to_check : str ,
409
409
excluded_file_paths : str ,
@@ -415,8 +415,8 @@ def main(
415
415
----------
416
416
function : Callable
417
417
Function to execute for the specified validation type.
418
- source_path : str
419
- Source file_path representing file_path to a file/directory .
418
+ source_paths : list of str
419
+ File paths of files and directories to check .
420
420
output_format : str
421
421
Output format of the error message.
422
422
file_extensions_to_check : str
@@ -434,7 +434,7 @@ def main(
434
434
ValueError
435
435
If the `source_path` is not pointing to existing file/directory.
436
436
"""
437
- if not os .path .exists (source_path ):
437
+ if not all ( os .path .exists (path ) for path in source_paths ):
438
438
raise ValueError ("Please enter a valid path, pointing to a file/directory." )
439
439
440
440
FILE_EXTENSIONS_TO_CHECK : FrozenSet [str ] = frozenset (
@@ -463,21 +463,22 @@ def is_ignored(path: str):
463
463
path = os .path .abspath (os .path .normpath (path ))
464
464
return any (path .startswith (ignored_path ) for ignored_path in PATHS_TO_IGNORE )
465
465
466
- if os .path .isfile (source_path ):
467
- check_file (source_path )
468
- else :
469
- for subdir , _ , files in os .walk (source_path ):
470
- if is_ignored (subdir ):
471
- continue
472
- for file_name in files :
473
- file_path = os .path .join (subdir , file_name )
474
- if is_ignored (file_path ) or not any (
475
- file_name .endswith (extension )
476
- for extension in FILE_EXTENSIONS_TO_CHECK
477
- ):
466
+ for source_path in source_paths :
467
+ if os .path .isfile (source_path ):
468
+ check_file (source_path )
469
+ else :
470
+ for subdir , _ , files in os .walk (source_path ):
471
+ if is_ignored (subdir ):
478
472
continue
473
+ for file_name in files :
474
+ file_path = os .path .join (subdir , file_name )
475
+ if is_ignored (file_path ) or not any (
476
+ file_name .endswith (extension )
477
+ for extension in FILE_EXTENSIONS_TO_CHECK
478
+ ):
479
+ continue
479
480
480
- check_file (file_path )
481
+ check_file (file_path )
481
482
482
483
return is_failed
483
484
@@ -494,7 +495,13 @@ def is_ignored(path: str):
494
495
parser = argparse .ArgumentParser (description = "Unwanted patterns checker." )
495
496
496
497
parser .add_argument (
497
- "path" , nargs = "?" , default = "." , help = "Source path of file/directory to check."
498
+ "paths" ,
499
+ nargs = "*" ,
500
+ default = ["." ],
501
+ help = (
502
+ "Source path(s) of files and directories to check. If a directory is "
503
+ "specified, all its contents are checked recursively."
504
+ ),
498
505
)
499
506
parser .add_argument (
500
507
"--format" ,
@@ -525,7 +532,7 @@ def is_ignored(path: str):
525
532
sys .exit (
526
533
main (
527
534
function = globals ().get (args .validation_type ), # type: ignore
528
- source_path = args .path ,
535
+ source_paths = args .paths ,
529
536
output_format = args .format ,
530
537
file_extensions_to_check = args .included_file_extensions ,
531
538
excluded_file_paths = args .excluded_file_paths ,
0 commit comments