From e7363070f159e99a8d061ba7b84631378600b508 Mon Sep 17 00:00:00 2001 From: pydn <25550995+pydn@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:48:43 -0500 Subject: [PATCH 1/2] Made updates to check for missing required arguments and for cases when unique id is passed through kwargs. --- comfyui_to_python.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/comfyui_to_python.py b/comfyui_to_python.py index 9b61692..6e75e40 100644 --- a/comfyui_to_python.py +++ b/comfyui_to_python.py @@ -211,8 +211,18 @@ def generate_workflow( for idx, data, is_special_function in load_order: # Generate class definition and inputs from the data inputs, class_type = data["inputs"], data["class_type"] + input_types = self.node_class_mappings[class_type].INPUT_TYPES() class_def = self.node_class_mappings[class_type]() + # If required inputs are not present, skip the node as it will break the code if passed through to the script + missing_required_variable = False + if "required" in input_types.keys(): + for required in input_types["required"]: + if required not in inputs.keys(): + missing_required_variable = True + if missing_required_variable: + continue + # If the class hasn't been initialized yet, initialize it and generate the import statements if class_type not in initialized_objects: # No need to use preview image nodes since we are executing the script in a terminal @@ -242,7 +252,12 @@ def generate_workflow( if no_params or key in class_def_params } # Deal with hidden variables - if class_def_params is not None: + if ( + "hidden" in input_types.keys() + and "unique_id" in input_types["hidden"].keys() + ): + inputs["unique_id"] = random.randint(1, 2**64) + elif class_def_params is not None: if "unique_id" in class_def_params: inputs["unique_id"] = random.randint(1, 2**64) @@ -260,6 +275,15 @@ def generate_workflow( **inputs, ) ) + print( + self.create_function_call_code( + initialized_objects[class_type], + class_def.FUNCTION, + executed_variables[idx], + is_special_function, + **inputs, + ) + ) else: code.append( self.create_function_call_code( @@ -270,6 +294,15 @@ def generate_workflow( **inputs, ) ) + print( + self.create_function_call_code( + initialized_objects[class_type], + class_def.FUNCTION, + executed_variables[idx], + is_special_function, + **inputs, + ) + ) # Generate final code by combining imports and code, and wrap them in a main function final_code = self.assemble_python_code( From ea32a8fbbe6c8726815a932b3dbb26de69b93f0a Mon Sep 17 00:00:00 2001 From: pydn <25550995+pydn@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:52:36 -0500 Subject: [PATCH 2/2] Remove unneeded print statements. --- comfyui_to_python.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/comfyui_to_python.py b/comfyui_to_python.py index 6e75e40..ec9566e 100644 --- a/comfyui_to_python.py +++ b/comfyui_to_python.py @@ -275,15 +275,6 @@ def generate_workflow( **inputs, ) ) - print( - self.create_function_call_code( - initialized_objects[class_type], - class_def.FUNCTION, - executed_variables[idx], - is_special_function, - **inputs, - ) - ) else: code.append( self.create_function_call_code( @@ -294,15 +285,6 @@ def generate_workflow( **inputs, ) ) - print( - self.create_function_call_code( - initialized_objects[class_type], - class_def.FUNCTION, - executed_variables[idx], - is_special_function, - **inputs, - ) - ) # Generate final code by combining imports and code, and wrap them in a main function final_code = self.assemble_python_code(