10
10
11
11
from typing import Dict , List , Any , Callable , Tuple
12
12
13
- from utils import import_custom_nodes , add_comfyui_directories_to_sys_path
13
+ from utils import import_custom_nodes , add_comfyui_directory_to_sys_path , get_value_at_index
14
14
15
15
16
16
sys .path .append ('../' )
@@ -218,7 +218,7 @@ def generate_workflow(self, load_order: List, filename: str = 'generated_code_wo
218
218
continue
219
219
220
220
class_type , import_statement , class_code = self .get_class_info (class_type )
221
- initialized_objects [class_type ] = class_type .lower ()
221
+ initialized_objects [class_type ] = class_type .lower (). strip ()
222
222
if class_type in self .base_node_class_mappings .keys ():
223
223
import_statements .add (import_statement )
224
224
if class_type not in self .base_node_class_mappings .keys ():
@@ -232,7 +232,7 @@ def generate_workflow(self, load_order: List, filename: str = 'generated_code_wo
232
232
inputs = {key : value for key , value in inputs .items () if key in class_def_params }
233
233
234
234
# Create executed variable and generate code
235
- executed_variables [idx ] = f'{ class_type .lower ()} _{ idx } '
235
+ executed_variables [idx ] = f'{ class_type .lower (). strip () } _{ idx } '
236
236
inputs = self .update_inputs (inputs , executed_variables )
237
237
238
238
if is_special_function :
@@ -302,14 +302,16 @@ def assemble_python_code(self, import_statements: set, speical_functions_code: L
302
302
Returns:
303
303
str: Generated final code as a string.
304
304
"""
305
- # Get the source code of the function as a string
306
- add_comfyui_directories_to_sys_path_code = inspect .getsource (add_comfyui_directories_to_sys_path )
305
+ # Get the source code of the utils functions as a string
306
+ func_strings = []
307
+ for func in [add_comfyui_directory_to_sys_path , get_value_at_index ]:
308
+ func_strings .append (f'\n { inspect .getsource (func )} ' )
307
309
# Define static import statements required for the script
308
- static_imports = ['import os' , 'import random' , 'import sys' , 'import torch' , f' \n { add_comfyui_directories_to_sys_path_code } ' ,
309
- ' \n \n add_comfyui_directories_to_sys_path ()' ]
310
+ static_imports = ['import os' , 'import random' , 'import sys' , 'from typing import Sequence, Mapping, Any, Union ' ,
311
+ 'import torch' ] + func_strings + [ ' \n \n add_comfyui_directory_to_sys_path ()' ]
310
312
# Check if custom nodes should be included
311
313
if custom_nodes :
312
- static_imports .append (' \n from utils import import_custom_nodes, get_value_at_index \n ' )
314
+ static_imports .append (f' \n { inspect . getsource ( import_custom_nodes ) } \n ' )
313
315
custom_nodes = 'import_custom_nodes()\n \t '
314
316
else :
315
317
custom_nodes = ''
@@ -336,9 +338,9 @@ def get_class_info(self, class_type: str) -> Tuple[str, str, str]:
336
338
"""
337
339
import_statement = class_type
338
340
if class_type in self .base_node_class_mappings .keys ():
339
- class_code = f'{ class_type .lower ()} = { class_type } ()'
341
+ class_code = f'{ class_type .lower (). strip () } = { class_type . strip () } ()'
340
342
else :
341
- class_code = f'{ class_type .lower ()} = NODE_CLASS_MAPPINGS["{ class_type } "]()'
343
+ class_code = f'{ class_type .lower (). strip () } = NODE_CLASS_MAPPINGS["{ class_type } "]()'
342
344
343
345
return class_type , import_statement , class_code
344
346
0 commit comments