|
20 | 20 | FILE_EXTENSIONS_TO_CHECK = (".py", ".pyx", ".pyx.ini", ".pxd")
|
21 | 21 |
|
22 | 22 |
|
23 |
| -def main( |
24 |
| - function: Callable[[str], Generator[Tuple[str, int, str], None, None]], |
25 |
| - source_path: str, |
26 |
| - output_format: str, |
27 |
| -) -> bool: |
28 |
| - """ |
29 |
| - Main entry point of the script. |
30 |
| -
|
31 |
| - Parameters |
32 |
| - ---------- |
33 |
| - function : Callable |
34 |
| - Function to execute for the test case. |
35 |
| - source_path : str |
36 |
| - Source path representing path to a file/directory. |
37 |
| - output_format : str |
38 |
| - Output format of the error message. |
39 |
| -
|
40 |
| - Returns |
41 |
| - ------- |
42 |
| - bool |
43 |
| - True if found any patterns are found related to the given function. |
44 |
| -
|
45 |
| - Raises |
46 |
| - ------ |
47 |
| - ValueError |
48 |
| - If the `source_path` is not pointing to existing file/directory. |
49 |
| - """ |
50 |
| - if not os.path.exists(source_path): |
51 |
| - raise ValueError( |
52 |
| - "Please enter a valid path, pointing to a valid file/directory." |
53 |
| - ) |
54 |
| - |
55 |
| - is_failed: bool = False |
56 |
| - |
57 |
| - if os.path.isfile(source_path): |
58 |
| - for source_path, line_number, msg in function(source_path): |
59 |
| - is_failed = True |
60 |
| - print( |
61 |
| - output_format.format( |
62 |
| - source_path=source_path, line_number=line_number, msg=msg |
63 |
| - ) |
64 |
| - ) |
65 |
| - |
66 |
| - for subdir, _, files in os.walk(source_path): |
67 |
| - for file_name in files: |
68 |
| - if any( |
69 |
| - file_name.endswith(extension) for extension in FILE_EXTENSIONS_TO_CHECK |
70 |
| - ): |
71 |
| - for source_path, line_number, msg in function( |
72 |
| - os.path.join(subdir, file_name) |
73 |
| - ): |
74 |
| - is_failed = True |
75 |
| - print( |
76 |
| - output_format.format( |
77 |
| - source_path=source_path, line_number=line_number, msg=msg |
78 |
| - ) |
79 |
| - ) |
80 |
| - return is_failed |
81 |
| - |
82 |
| - |
83 | 23 | def strings_to_concatenate(
|
84 | 24 | source_path: str,
|
85 | 25 | ) -> Generator[Tuple[str, int, str], None, None]:
|
@@ -242,6 +182,66 @@ def bare_pytest_raises(source_path: str) -> Generator[Tuple[str, int, str], None
|
242 | 182 | break
|
243 | 183 |
|
244 | 184 |
|
| 185 | +def main( |
| 186 | + function: Callable[[str], Generator[Tuple[str, int, str], None, None]], |
| 187 | + source_path: str, |
| 188 | + output_format: str, |
| 189 | +) -> bool: |
| 190 | + """ |
| 191 | + Main entry point of the script. |
| 192 | +
|
| 193 | + Parameters |
| 194 | + ---------- |
| 195 | + function : Callable |
| 196 | + Function to execute for the test case. |
| 197 | + source_path : str |
| 198 | + Source path representing path to a file/directory. |
| 199 | + output_format : str |
| 200 | + Output format of the error message. |
| 201 | +
|
| 202 | + Returns |
| 203 | + ------- |
| 204 | + bool |
| 205 | + True if found any patterns are found related to the given function. |
| 206 | +
|
| 207 | + Raises |
| 208 | + ------ |
| 209 | + ValueError |
| 210 | + If the `source_path` is not pointing to existing file/directory. |
| 211 | + """ |
| 212 | + if not os.path.exists(source_path): |
| 213 | + raise ValueError( |
| 214 | + "Please enter a valid path, pointing to a valid file/directory." |
| 215 | + ) |
| 216 | + |
| 217 | + is_failed: bool = False |
| 218 | + |
| 219 | + if os.path.isfile(source_path): |
| 220 | + for source_path, line_number, msg in function(source_path): |
| 221 | + is_failed = True |
| 222 | + print( |
| 223 | + output_format.format( |
| 224 | + source_path=source_path, line_number=line_number, msg=msg |
| 225 | + ) |
| 226 | + ) |
| 227 | + |
| 228 | + for subdir, _, files in os.walk(source_path): |
| 229 | + for file_name in files: |
| 230 | + if any( |
| 231 | + file_name.endswith(extension) for extension in FILE_EXTENSIONS_TO_CHECK |
| 232 | + ): |
| 233 | + for source_path, line_number, msg in function( |
| 234 | + os.path.join(subdir, file_name) |
| 235 | + ): |
| 236 | + is_failed = True |
| 237 | + print( |
| 238 | + output_format.format( |
| 239 | + source_path=source_path, line_number=line_number, msg=msg |
| 240 | + ) |
| 241 | + ) |
| 242 | + return is_failed |
| 243 | + |
| 244 | + |
245 | 245 | if __name__ == "__main__":
|
246 | 246 | available_validation_types = [
|
247 | 247 | f.__name__
|
|
0 commit comments