Added missing documentation in docstrings.
This commit is contained in:
@@ -203,20 +203,21 @@ def get_class_info(class_type: str) -> (str, str, str):
|
||||
return class_type, import_statement, class_code
|
||||
|
||||
|
||||
def assemble_python_code(import_statements: set, loader_code: List[str], code: List[str], query_size: int) -> str:
|
||||
def assemble_python_code(import_statements: set, loader_code: List[str], code: List[str], queue_size: int) -> str:
|
||||
"""
|
||||
Generates final code string.
|
||||
|
||||
Args:
|
||||
import_statements (set): A set of unique import statements
|
||||
code (List[str]): A list of code strings
|
||||
queue_size (int): Number of photos that will be generated by the script.
|
||||
|
||||
Returns:
|
||||
final_code (str): Generated final code as a string
|
||||
"""
|
||||
static_imports = ['import random']
|
||||
imports_code = [f"from nodes import {class_name}" for class_name in import_statements]
|
||||
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)
|
||||
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)
|
||||
final_code = '\n'.join(static_imports + ['import sys\nsys.path.append("../")'] + imports_code + ['', main_function_code, '', 'if __name__ == "__main__":', '\tmain()'])
|
||||
|
||||
return final_code
|
||||
@@ -243,14 +244,14 @@ def write_code_to_file(filename: str, code: str) -> None:
|
||||
file.write(code)
|
||||
|
||||
|
||||
def get_function_parameters(func: Callable[..., Any]) -> List:
|
||||
def get_function_parameters(func: Callable) -> List:
|
||||
"""Get the names of a function's parameters.
|
||||
|
||||
Args:
|
||||
func (Callable[..., Any]): The function whose parameters we want to inspect.
|
||||
func (Callable): The function whose parameters we want to inspect.
|
||||
|
||||
Returns:
|
||||
List: A dictionary containing the names of the function's parameters.
|
||||
List: A list containing the names of the function's parameters.
|
||||
"""
|
||||
signature = inspect.signature(func)
|
||||
parameters = {name: param.default if param.default != param.empty else None
|
||||
@@ -258,7 +259,7 @@ def get_function_parameters(func: Callable[..., Any]) -> List:
|
||||
return list(parameters.keys())
|
||||
|
||||
|
||||
def generate_workflow(load_order: List, filename: str = 'generated_code_workflow.py', query_size: int = 10) -> str:
|
||||
def generate_workflow(load_order: List, filename: str = 'generated_code_workflow.py', queue_size: int = 10) -> str:
|
||||
"""
|
||||
Generate the execution code based on the load order.
|
||||
|
||||
@@ -266,6 +267,7 @@ def generate_workflow(load_order: List, filename: str = 'generated_code_workflow
|
||||
load_order (List): A list of tuples representing the load order.
|
||||
filename (str): The name of the Python file to which the code should be saved.
|
||||
Defaults to 'generated_code_workflow.py'.
|
||||
queue_size (int): The number of photos that will be created by the script.
|
||||
|
||||
Returns:
|
||||
str: Generated execution code as a string.
|
||||
@@ -306,7 +308,7 @@ def generate_workflow(load_order: List, filename: str = 'generated_code_workflow
|
||||
code.append(create_function_call_code(initialized_objects[class_type], class_def.FUNCTION, executed_variables[idx], is_loader, **inputs))
|
||||
|
||||
# Generate final code by combining imports and code, and wrap them in a main function
|
||||
final_code = assemble_python_code(import_statements, loader_code, code, query_size)
|
||||
final_code = assemble_python_code(import_statements, loader_code, code, queue_size)
|
||||
|
||||
# Save the code to a .py file
|
||||
write_code_to_file(filename, final_code)
|
||||
@@ -314,7 +316,7 @@ def generate_workflow(load_order: List, filename: str = 'generated_code_workflow
|
||||
return final_code
|
||||
|
||||
|
||||
def main(input, query_size=10):
|
||||
def main(input, queue_size=10):
|
||||
"""
|
||||
Main function to be executed.
|
||||
"""
|
||||
@@ -322,11 +324,11 @@ def main(input, query_size=10):
|
||||
prompt = read_json_file(input)
|
||||
load_order = determine_load_order(prompt)
|
||||
output_file = input.replace('.json', '.py')
|
||||
code = generate_workflow(load_order, filename=output_file, query_size=query_size)
|
||||
code = generate_workflow(load_order, filename=output_file, queue_size=queue_size)
|
||||
logging.info(code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
input = 'workflow_api.json'
|
||||
query_size = 10
|
||||
main(input, query_size)
|
||||
queue_size = 10
|
||||
main(input, queue_size)
|
||||
|
||||
Reference in New Issue
Block a user