-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
CI: Add test case for unwanted patterns #30467
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
Changes from 1 commit
272099b 7a588bc c19a2a5 2b67601 605e70c 0530d02 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||
| #!/usr/bin/env python3 | ||||||||
| #!/usr/bin/env python | ||||||||
| """ | ||||||||
| GH #30454 | ||||||||
| | ||||||||
| | @@ -12,7 +12,6 @@ | |||||||
| ... "baz" | ||||||||
| ... ) | ||||||||
| | ||||||||
| | ||||||||
| into this: | ||||||||
| | ||||||||
| >>> foo = ("bar " "baz") | ||||||||
| | @@ -22,65 +21,102 @@ | |||||||
| so we are checking it here. | ||||||||
| """ | ||||||||
| | ||||||||
| import argparse | ||||||||
| import os | ||||||||
| import sys | ||||||||
| import token | ||||||||
| import tokenize | ||||||||
| from typing import FrozenSet, Generator, List | ||||||||
| from typing import Dict, Generator, List | ||||||||
| | ||||||||
| FILE_EXTENSIONS_TO_CHECK = (".py", ".pyx", ".pyx.ini", ".pxd") | ||||||||
| | ||||||||
| FILE_EXTENSIONS_TO_CHECK: FrozenSet[str] = frozenset( | ||||||||
| (".pxd", ".py", ".pyx", ".pyx.ini") | ||||||||
| ) | ||||||||
| | ||||||||
| def main(source_path: str, output_format: str) -> bool: | ||||||||
| """ | ||||||||
| Main entry point of the script. | ||||||||
| | ||||||||
| Parameters | ||||||||
| ---------- | ||||||||
| source_path : str, default '.' | ||||||||
| Source path representing path to a file/directory. | ||||||||
| output_format : str | ||||||||
| Output format of the script. | ||||||||
| | ||||||||
| Returns | ||||||||
| ------- | ||||||||
| bool | ||||||||
| True if found any strings that needs to be concatenated. | ||||||||
| | ||||||||
| def strings_to_concatenate(file_path: str) -> Generator[str, None, None]: | ||||||||
| Raises | ||||||||
| ------ | ||||||||
| ValueError | ||||||||
| If the `source_path` is not pointing to existing file/directory. | ||||||||
| """ | ||||||||
| if not os.path.exists(source_path): | ||||||||
| raise ValueError( | ||||||||
| "Please enter a valid path, pointing to a valid file/directory." | ||||||||
| ) | ||||||||
| | ||||||||
| is_failed: bool = False | ||||||||
| | ||||||||
| if os.path.isfile(source_path): | ||||||||
| for values in strings_to_concatenate(source_path): | ||||||||
| is_failed = True | ||||||||
| print(output_format.format(**values)) | ||||||||
| | ||||||||
| for subdir, _, files in os.walk(source_path): | ||||||||
| for file_name in files: | ||||||||
| if any( | ||||||||
| file_name.endswith(extension) for extension in FILE_EXTENSIONS_TO_CHECK | ||||||||
| ): | ||||||||
| for values in strings_to_concatenate(os.path.join(subdir, file_name)): | ||||||||
| is_failed = True | ||||||||
| print(output_format.format(**values)) | ||||||||
| ||||||||
| print(output_format.format(**values)) | |
| msg = "String unnecessarily split in two by black. Please merge them manually." | |
| print(output_format.format(source_path=source_path, line_number=line_number, msg=msg)) |
And since now the strings_to_concatenate function is just returning two values, I think it makes more sense to return a tuple with them, instead of a dict, so the for above would be:
for source_path, line_number in strings_to_concatenate(os.path.join(subdir, file_name)):
Uh oh!
There was an error while loading. Please reload this page.