Skip to content

Commit e18efbb

Browse files
author
MomIsBestFriend
committed
Moved "main" function to the bottom (Above 'if __name__ == "__main__"')
1 parent 2b61e53 commit e18efbb

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

scripts/validate_string_concatenation.py

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,66 +20,6 @@
2020
FILE_EXTENSIONS_TO_CHECK = (".py", ".pyx", ".pyx.ini", ".pxd")
2121

2222

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-
8323
def strings_to_concatenate(
8424
source_path: str,
8525
) -> Generator[Tuple[str, int, str], None, None]:
@@ -242,6 +182,66 @@ def bare_pytest_raises(source_path: str) -> Generator[Tuple[str, int, str], None
242182
break
243183

244184

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+
245245
if __name__ == "__main__":
246246
available_validation_types = [
247247
f.__name__

0 commit comments

Comments
 (0)