From 72f4a36be5b52a02bbacf0361ff9ae837d224a3f Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 11 Apr 2020 16:32:42 +0300 Subject: [PATCH 1/6] Added option to ignore file paths --- scripts/validate_unwanted_patterns.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py index 193fef026a96b..fc38197aa59d7 100755 --- a/scripts/validate_unwanted_patterns.py +++ b/scripts/validate_unwanted_patterns.py @@ -293,6 +293,7 @@ def main( source_path: str, output_format: str, file_extensions_to_check: str, + excluded_file_paths: str, ) -> bool: """ Main entry point of the script. @@ -305,6 +306,10 @@ def main( Source path representing path to a file/directory. output_format : str Output format of the error message. + file_extensions_to_check: str + Coma seperated values of what file extensions to check. + excluded_file_paths: str + Coma seperated values of what file paths to exclude during the check. Returns ------- @@ -322,13 +327,9 @@ def main( is_failed: bool = False file_path: str = "" - FILE_EXTENSIONS_TO_CHECK: FrozenSet[str] = frozenset( - file_extensions_to_check.split(",") - ) - if os.path.isfile(source_path): file_path = source_path - with open(file_path, "r") as file_obj: + with open(file_path, mode="r") as file_obj: for line_number, msg in function(file_obj): is_failed = True print( @@ -337,9 +338,15 @@ def main( ) ) + FILE_EXTENSIONS_TO_CHECK: FrozenSet[str] = frozenset( + file_extensions_to_check.split(",") + ) + PATHS_TO_IGNORE: FrozenSet[str] = frozenset(excluded_file_paths.split(",")) + for subdir, _, files in os.walk(source_path): if any(path in subdir for path in PATHS_TO_IGNORE): continue + for file_name in files: if not any( file_name.endswith(extension) for extension in FILE_EXTENSIONS_TO_CHECK @@ -347,7 +354,7 @@ def main( continue file_path = os.path.join(subdir, file_name) - with open(file_path, "r") as file_obj: + with open(file_path, mode="r") as file_obj: for line_number, msg in function(file_obj): is_failed = True print( @@ -389,6 +396,11 @@ def main( default="py,pyx,pxd,pxi", help="Coma seperated file extensions to check.", ) + parser.add_argument( + "--excluded-file-paths", + default="asv_bench/env", + help="Coma seperated file extensions to check.", + ) args = parser.parse_args() @@ -398,5 +410,6 @@ def main( source_path=args.path, output_format=args.format, file_extensions_to_check=args.included_file_extensions, + excluded_file_paths=args.excluded_file_paths, ) ) From b167703a0df9db04e77ddb87616da7cecd5b00c5 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 11 Apr 2020 16:57:08 +0300 Subject: [PATCH 2/6] Deleted hard-coded ignore_file_paths --- scripts/validate_unwanted_patterns.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py index fc38197aa59d7..72c487476bbc8 100755 --- a/scripts/validate_unwanted_patterns.py +++ b/scripts/validate_unwanted_patterns.py @@ -18,8 +18,6 @@ import tokenize from typing import IO, Callable, FrozenSet, Iterable, List, Tuple -PATHS_TO_IGNORE: Tuple[str, ...] = ("asv_bench/env",) - def _get_literal_string_prefix_len(token_string: str) -> int: """ From 1b6e14f5c0647d08c3d3f0f704ea98f4f1c3245d Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 11 Apr 2020 17:38:16 +0300 Subject: [PATCH 3/6] (EMPTY COMMIT) Restarting CI From b26382d887c85f94e0fe99ae666aae1dad73ecd3 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 24 Apr 2020 13:00:45 +0300 Subject: [PATCH 4/6] Removed mode="r" xref: https://github.com/pandas-dev/pandas/pull/33479#discussion_r409899437 --- scripts/validate_unwanted_patterns.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py index 72c487476bbc8..d15dfba5a0d4c 100755 --- a/scripts/validate_unwanted_patterns.py +++ b/scripts/validate_unwanted_patterns.py @@ -327,7 +327,7 @@ def main( if os.path.isfile(source_path): file_path = source_path - with open(file_path, mode="r") as file_obj: + with open(file_path) as file_obj: for line_number, msg in function(file_obj): is_failed = True print( @@ -352,7 +352,7 @@ def main( continue file_path = os.path.join(subdir, file_name) - with open(file_path, mode="r") as file_obj: + with open(file_path) as file_obj: for line_number, msg in function(file_obj): is_failed = True print( From 99d1cf1674909a7d45ad72461760d8eaed063932 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 24 Apr 2020 13:01:59 +0300 Subject: [PATCH 5/6] Grammer xref: https://github.com/pandas-dev/pandas/pull/33479#discussion_r409899683 --- scripts/validate_unwanted_patterns.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py index d15dfba5a0d4c..4c61cdf167da7 100755 --- a/scripts/validate_unwanted_patterns.py +++ b/scripts/validate_unwanted_patterns.py @@ -392,12 +392,12 @@ def main( parser.add_argument( "--included-file-extensions", default="py,pyx,pxd,pxi", - help="Coma seperated file extensions to check.", + help="Comma separated file extensions to check.", ) parser.add_argument( "--excluded-file-paths", default="asv_bench/env", - help="Coma seperated file extensions to check.", + help="Comma separated file extensions to check.", ) args = parser.parse_args() From d72e1b5a457ba161664eb2e9b53a34e1daaa6c46 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <50263213+MomIsBestFriend@users.noreply.github.com> Date: Fri, 24 Apr 2020 13:00:34 +0300 Subject: [PATCH 6/6] Apply suggestions from code review Co-Authored-By: William Ayd --- scripts/validate_unwanted_patterns.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py index 4c61cdf167da7..16bf9a677641a 100755 --- a/scripts/validate_unwanted_patterns.py +++ b/scripts/validate_unwanted_patterns.py @@ -336,10 +336,10 @@ def main( ) ) - FILE_EXTENSIONS_TO_CHECK: FrozenSet[str] = frozenset( + FILE_EXTENSIONS_TO_CHECK = frozenset( file_extensions_to_check.split(",") ) - PATHS_TO_IGNORE: FrozenSet[str] = frozenset(excluded_file_paths.split(",")) + PATHS_TO_IGNORE = frozenset(excluded_file_paths.split(",")) for subdir, _, files in os.walk(source_path): if any(path in subdir for path in PATHS_TO_IGNORE):