Defer generated ComfyUI bootstrap until execution

This commit is contained in:
Peyton DeNiro
2026-03-29 14:40:17 -05:00
parent d751147ed9
commit 441dcfebdf
3 changed files with 68 additions and 44 deletions
+13 -9
View File
@@ -47,10 +47,6 @@ class WorkflowRenderer:
"import sys",
"from typing import Sequence, Mapping, Any, Union",
] + func_strings
static_imports.append("\n# Runtime support")
static_imports.append(
"\nbootstrap_comfyui_runtime()\nimport torch\nadd_extra_model_paths()\n"
)
if plan.custom_nodes:
static_imports.append(f"\n{inspect.getsource(import_custom_nodes)}\n")
@@ -76,17 +72,25 @@ class WorkflowRenderer:
"extra_pnginfo = build_extra_pnginfo()",
]
execution_section = ["# Workflow execution"]
execution_section = [
"# Workflow execution",
"def main():",
" bootstrap_comfyui_runtime()",
" import torch",
"",
" add_extra_model_paths()",
]
if custom_nodes_call:
execution_section.append(f" {custom_nodes_call}")
if imports_code:
execution_section.extend(["# Node imports", *imports_code, ""])
execution_section.extend(["", " # Node imports"])
execution_section.extend(f" {line}" for line in imports_code)
execution_section.extend(
[
"def main():",
"",
" with torch.inference_mode():",
]
)
if custom_nodes_call:
execution_section.append(f" {custom_nodes_call}")
execution_section.extend(
self.build_function_body(
plan.special_functions_code, "pass", indentation=" "