Skip to content

Commit c1c4bcf

Browse files
committed
BLD: fix ignored path checking in validate_unwanted_patterns.py
The previous behaviour filtered out too many paths: any subdirectory whose relative path *contained* any of the ignored paths (which could be arbitrary strings) would be ignored. E.g., if PATHS_TO_IGNORE contained "foo", all of "./foo", "./spam/foo", "./spam/foo/eggs", "./barfoobaz", "./spam/foo.py" would get filtered out. On the other hand, individual files that *did* appear in the PAHTS_TO_IGNORE were *not* ignored. Now the behaviour should be a bit more robust. Ignored file pahts can be specified as relative paths or absolute paths (since they are all passed through os.path.abspath); any files below a subdirectory included in PATHS_TO_IGNORE will be filtered out, and so will any files which are explicitly mentioned in PATHS_TO_IGNORE.
1 parent 23ad3e7 commit c1c4bcf

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

scripts/validate_unwanted_patterns.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,24 @@ def check_file(file_path: str):
459459
)
460460
)
461461

462+
def is_ignored(path: str):
463+
path = os.path.abspath(os.path.normpath(path))
464+
return any(path.startswith(ignored_path) for ignored_path in PATHS_TO_IGNORE)
465+
462466
if os.path.isfile(source_path):
463467
check_file(source_path)
464468
else:
465469
for subdir, _, files in os.walk(source_path):
466-
if any(path in subdir for path in PATHS_TO_IGNORE):
470+
if is_ignored(subdir):
467471
continue
468472
for file_name in files:
469-
if not any(
473+
file_path = os.path.join(subdir, file_name)
474+
if is_ignored(file_path) or not any(
470475
file_name.endswith(extension)
471476
for extension in FILE_EXTENSIONS_TO_CHECK
472477
):
473478
continue
474479

475-
file_path = os.path.join(subdir, file_name)
476480
check_file(file_path)
477481

478482
return is_failed

0 commit comments

Comments
 (0)