Skip to content

Commit c799ce6

Browse files
author
Peyton
committed
Added missing documentation in docstrings.
1 parent 5f24418 commit c799ce6

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

script_examples/generate_python_code.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,21 @@ def get_class_info(class_type: str) -> (str, str, str):
203203
return class_type, import_statement, class_code
204204

205205

206-
def assemble_python_code(import_statements: set, loader_code: List[str], code: List[str], query_size: int) -> str:
206+
def assemble_python_code(import_statements: set, loader_code: List[str], code: List[str], queue_size: int) -> str:
207207
"""
208208
Generates final code string.
209209
210210
Args:
211211
import_statements (set): A set of unique import statements
212212
code (List[str]): A list of code strings
213+
queue_size (int): Number of photos that will be generated by the script.
213214
214215
Returns:
215216
final_code (str): Generated final code as a string
216217
"""
217218
static_imports = ['import random']
218219
imports_code = [f"from nodes import {class_name}" for class_name in import_statements]
219-
main_function_code = f"def main():\n\t" + '\n\t'.join(loader_code) + f'\n\tfor q in {range(1, query_size)}:\n\t' + '\n\t'.join(code)
220+
main_function_code = f"def main():\n\t" + '\n\t'.join(loader_code) + f'\n\tfor q in {range(1, queue_size)}:\n\t' + '\n\t'.join(code)
220221
final_code = '\n'.join(static_imports + ['import sys\nsys.path.append("../")'] + imports_code + ['', main_function_code, '', 'if __name__ == "__main__":', '\tmain()'])
221222

222223
return final_code
@@ -243,29 +244,30 @@ def write_code_to_file(filename: str, code: str) -> None:
243244
file.write(code)
244245

245246

246-
def get_function_parameters(func: Callable[..., Any]) -> List:
247+
def get_function_parameters(func: Callable) -> List:
247248
"""Get the names of a function's parameters.
248249
249250
Args:
250-
func (Callable[..., Any]): The function whose parameters we want to inspect.
251+
func (Callable): The function whose parameters we want to inspect.
251252
252253
Returns:
253-
List: A dictionary containing the names of the function's parameters.
254+
List: A list containing the names of the function's parameters.
254255
"""
255256
signature = inspect.signature(func)
256257
parameters = {name: param.default if param.default != param.empty else None
257258
for name, param in signature.parameters.items()}
258259
return list(parameters.keys())
259260

260261

261-
def generate_workflow(load_order: List, filename: str = 'generated_code_workflow.py', query_size: int = 10) -> str:
262+
def generate_workflow(load_order: List, filename: str = 'generated_code_workflow.py', queue_size: int = 10) -> str:
262263
"""
263264
Generate the execution code based on the load order.
264265
265266
Args:
266267
load_order (List): A list of tuples representing the load order.
267268
filename (str): The name of the Python file to which the code should be saved.
268269
Defaults to 'generated_code_workflow.py'.
270+
queue_size (int): The number of photos that will be created by the script.
269271
270272
Returns:
271273
str: Generated execution code as a string.
@@ -306,27 +308,27 @@ def generate_workflow(load_order: List, filename: str = 'generated_code_workflow
306308
code.append(create_function_call_code(initialized_objects[class_type], class_def.FUNCTION, executed_variables[idx], is_loader, **inputs))
307309

308310
# Generate final code by combining imports and code, and wrap them in a main function
309-
final_code = assemble_python_code(import_statements, loader_code, code, query_size)
311+
final_code = assemble_python_code(import_statements, loader_code, code, queue_size)
310312

311313
# Save the code to a .py file
312314
write_code_to_file(filename, final_code)
313315

314316
return final_code
315317

316318

317-
def main(input, query_size=10):
319+
def main(input, queue_size=10):
318320
"""
319321
Main function to be executed.
320322
"""
321323
# Load JSON data from the input file
322324
prompt = read_json_file(input)
323325
load_order = determine_load_order(prompt)
324326
output_file = input.replace('.json', '.py')
325-
code = generate_workflow(load_order, filename=output_file, query_size=query_size)
327+
code = generate_workflow(load_order, filename=output_file, queue_size=queue_size)
326328
logging.info(code)
327329

328330

329331
if __name__ == '__main__':
330332
input = 'workflow_api.json'
331-
query_size = 10
332-
main(input, query_size)
333+
queue_size = 10
334+
main(input, queue_size)

0 commit comments

Comments
 (0)