@@ -416,7 +416,7 @@ def main(
416
416
function : Callable
417
417
Function to execute for the specified validation type.
418
418
source_path : str
419
- Source path representing path to a file/directory.
419
+ Source file_path representing file_path to a file/directory.
420
420
output_format : str
421
421
Output format of the error message.
422
422
file_extensions_to_check : str
@@ -437,16 +437,19 @@ def main(
437
437
if not os .path .exists (source_path ):
438
438
raise ValueError ("Please enter a valid path, pointing to a file/directory." )
439
439
440
- is_failed : bool = False
441
- file_path : str = ""
442
-
443
440
FILE_EXTENSIONS_TO_CHECK : FrozenSet [str ] = frozenset (
444
441
file_extensions_to_check .split ("," )
445
442
)
446
- PATHS_TO_IGNORE = frozenset (excluded_file_paths .split ("," ))
443
+ PATHS_TO_IGNORE = frozenset (
444
+ os .path .abspath (os .path .normpath (path ))
445
+ for path in excluded_file_paths .split ("," )
446
+ )
447
+
448
+ is_failed : bool = False
449
+
450
+ def check_file (file_path : str ):
451
+ nonlocal is_failed
447
452
448
- if os .path .isfile (source_path ):
449
- file_path = source_path
450
453
with open (file_path , "r" ) as file_obj :
451
454
for line_number , msg in function (file_obj ):
452
455
is_failed = True
@@ -456,24 +459,21 @@ def main(
456
459
)
457
460
)
458
461
459
- for subdir , _ , files in os .walk (source_path ):
460
- if any (path in subdir for path in PATHS_TO_IGNORE ):
461
- continue
462
- for file_name in files :
463
- if not any (
464
- file_name .endswith (extension ) for extension in FILE_EXTENSIONS_TO_CHECK
465
- ):
462
+ if os .path .isfile (source_path ):
463
+ check_file (source_path )
464
+ else :
465
+ for subdir , _ , files in os .walk (source_path ):
466
+ if any (path in subdir for path in PATHS_TO_IGNORE ):
466
467
continue
467
-
468
- file_path = os .path .join (subdir , file_name )
469
- with open (file_path , "r" ) as file_obj :
470
- for line_number , msg in function (file_obj ):
471
- is_failed = True
472
- print (
473
- output_format .format (
474
- source_path = file_path , line_number = line_number , msg = msg
475
- )
476
- )
468
+ for file_name in files :
469
+ if not any (
470
+ file_name .endswith (extension )
471
+ for extension in FILE_EXTENSIONS_TO_CHECK
472
+ ):
473
+ continue
474
+
475
+ file_path = os .path .join (subdir , file_name )
476
+ check_file (file_path )
477
477
478
478
return is_failed
479
479
0 commit comments