Skip to content

Commit

Permalink
Added option to include/ignore file extensions (#33216)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaharNaveh authored Apr 10, 2020
1 parent aa8e869 commit 48838da
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions scripts/validate_unwanted_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import sys
import token
import tokenize
from typing import IO, Callable, Iterable, List, Tuple
from typing import IO, Callable, FrozenSet, Iterable, List, Tuple

FILE_EXTENSIONS_TO_CHECK: Tuple[str, ...] = (".py", ".pyx", ".pxi.ini", ".pxd")
PATHS_TO_IGNORE: Tuple[str, ...] = ("asv_bench/env",)


Expand Down Expand Up @@ -293,6 +292,7 @@ def main(
function: Callable[[IO[str]], Iterable[Tuple[int, str]]],
source_path: str,
output_format: str,
file_extensions_to_check: str,
) -> bool:
"""
Main entry point of the script.
Expand Down Expand Up @@ -322,6 +322,10 @@ 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:
Expand Down Expand Up @@ -370,7 +374,7 @@ def main(
parser.add_argument(
"--format",
"-f",
default="{source_path}:{line_number}:{msg}.",
default="{source_path}:{line_number}:{msg}",
help="Output format of the error message.",
)
parser.add_argument(
Expand All @@ -380,6 +384,11 @@ def main(
required=True,
help="Validation test case to check.",
)
parser.add_argument(
"--included-file-extensions",
default="py,pyx,pxd,pxi",
help="Coma seperated file extensions to check.",
)

args = parser.parse_args()

Expand All @@ -388,5 +397,6 @@ def main(
function=globals().get(args.validation_type), # type: ignore
source_path=args.path,
output_format=args.format,
file_extensions_to_check=args.included_file_extensions,
)
)

0 comments on commit 48838da

Please sign in to comment.