Skip to content

Added option to ignore file paths #33479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions scripts/validate_unwanted_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -293,6 +291,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.
Expand All @@ -305,6 +304,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
-------
Expand All @@ -322,13 +325,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(
Expand All @@ -337,17 +336,23 @@ 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
):
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is making "mode" explicit necesary? its not a pattern we used elsewhere

for line_number, msg in function(file_obj):
is_failed = True
print(
Expand Down Expand Up @@ -389,6 +394,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.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coma -> Comma (i hope)
seperated -> separated

looks like both of these need fixing on L395 too

)

args = parser.parse_args()

Expand All @@ -398,5 +408,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,
)
)