Skip to content

Commit 48838da

Browse files
authored
Added option to include/ignore file extensions (#33216)
1 parent aa8e869 commit 48838da

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/validate_unwanted_patterns.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
import sys
1717
import token
1818
import tokenize
19-
from typing import IO, Callable, Iterable, List, Tuple
19+
from typing import IO, Callable, FrozenSet, Iterable, List, Tuple
2020

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

2423

@@ -293,6 +292,7 @@ def main(
293292
function: Callable[[IO[str]], Iterable[Tuple[int, str]]],
294293
source_path: str,
295294
output_format: str,
295+
file_extensions_to_check: str,
296296
) -> bool:
297297
"""
298298
Main entry point of the script.
@@ -322,6 +322,10 @@ def main(
322322
is_failed: bool = False
323323
file_path: str = ""
324324

325+
FILE_EXTENSIONS_TO_CHECK: FrozenSet[str] = frozenset(
326+
file_extensions_to_check.split(",")
327+
)
328+
325329
if os.path.isfile(source_path):
326330
file_path = source_path
327331
with open(file_path, "r") as file_obj:
@@ -370,7 +374,7 @@ def main(
370374
parser.add_argument(
371375
"--format",
372376
"-f",
373-
default="{source_path}:{line_number}:{msg}.",
377+
default="{source_path}:{line_number}:{msg}",
374378
help="Output format of the error message.",
375379
)
376380
parser.add_argument(
@@ -380,6 +384,11 @@ def main(
380384
required=True,
381385
help="Validation test case to check.",
382386
)
387+
parser.add_argument(
388+
"--included-file-extensions",
389+
default="py,pyx,pxd,pxi",
390+
help="Coma seperated file extensions to check.",
391+
)
383392

384393
args = parser.parse_args()
385394

@@ -388,5 +397,6 @@ def main(
388397
function=globals().get(args.validation_type), # type: ignore
389398
source_path=args.path,
390399
output_format=args.format,
400+
file_extensions_to_check=args.included_file_extensions,
391401
)
392402
)

0 commit comments

Comments
 (0)