Skip to content

Commit e736307

Browse files
committed
Made updates to check for missing required arguments and for cases when unique id is passed through kwargs.
1 parent 39c2229 commit e736307

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

comfyui_to_python.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,18 @@ def generate_workflow(
211211
for idx, data, is_special_function in load_order:
212212
# Generate class definition and inputs from the data
213213
inputs, class_type = data["inputs"], data["class_type"]
214+
input_types = self.node_class_mappings[class_type].INPUT_TYPES()
214215
class_def = self.node_class_mappings[class_type]()
215216

217+
# If required inputs are not present, skip the node as it will break the code if passed through to the script
218+
missing_required_variable = False
219+
if "required" in input_types.keys():
220+
for required in input_types["required"]:
221+
if required not in inputs.keys():
222+
missing_required_variable = True
223+
if missing_required_variable:
224+
continue
225+
216226
# If the class hasn't been initialized yet, initialize it and generate the import statements
217227
if class_type not in initialized_objects:
218228
# No need to use preview image nodes since we are executing the script in a terminal
@@ -242,7 +252,12 @@ def generate_workflow(
242252
if no_params or key in class_def_params
243253
}
244254
# Deal with hidden variables
245-
if class_def_params is not None:
255+
if (
256+
"hidden" in input_types.keys()
257+
and "unique_id" in input_types["hidden"].keys()
258+
):
259+
inputs["unique_id"] = random.randint(1, 2**64)
260+
elif class_def_params is not None:
246261
if "unique_id" in class_def_params:
247262
inputs["unique_id"] = random.randint(1, 2**64)
248263

@@ -260,6 +275,15 @@ def generate_workflow(
260275
**inputs,
261276
)
262277
)
278+
print(
279+
self.create_function_call_code(
280+
initialized_objects[class_type],
281+
class_def.FUNCTION,
282+
executed_variables[idx],
283+
is_special_function,
284+
**inputs,
285+
)
286+
)
263287
else:
264288
code.append(
265289
self.create_function_call_code(
@@ -270,6 +294,15 @@ def generate_workflow(
270294
**inputs,
271295
)
272296
)
297+
print(
298+
self.create_function_call_code(
299+
initialized_objects[class_type],
300+
class_def.FUNCTION,
301+
executed_variables[idx],
302+
is_special_function,
303+
**inputs,
304+
)
305+
)
273306

274307
# Generate final code by combining imports and code, and wrap them in a main function
275308
final_code = self.assemble_python_code(

0 commit comments

Comments
 (0)