Skip to content

Commit b4a20ac

Browse files
authored
feat: Support ComfyUI-Manager for pip version (Comfy-Org#7555)
1 parent c55dc85 commit b4a20ac

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

comfy/cli_args.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ class LatentPreviewMethod(enum.Enum):
121121
upcast.add_argument("--dont-upcast-attention", action="store_true", help="Disable all upcasting of attention. Should be unnecessary except for debugging.")
122122

123123

124+
parser.add_argument("--enable-manager", action="store_true", help="Enable the ComfyUI-Manager feature.")
125+
manager_group = parser.add_mutually_exclusive_group()
126+
manager_group.add_argument("--disable-manager-ui", action="store_true", help="Disables only the ComfyUI-Manager UI and endpoints. Scheduled installations and similar background tasks will still operate.")
127+
manager_group.add_argument("--enable-manager-legacy-ui", action="store_true", help="Enables the legacy UI of ComfyUI-Manager")
128+
129+
124130
vram_group = parser.add_mutually_exclusive_group()
125131
vram_group.add_argument("--gpu-only", action="store_true", help="Store and run everything (text encoders/CLIP models, etc... on the GPU).")
126132
vram_group.add_argument("--highvram", action="store_true", help="By default models will be unloaded to CPU memory after being used. This option keeps them in GPU memory.")
@@ -168,6 +174,7 @@ class PerformanceFeature(enum.Enum):
168174
parser.add_argument("--verbose", default='INFO', const='DEBUG', nargs="?", choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Set the logging level')
169175
parser.add_argument("--log-stdout", action="store_true", help="Send normal process output to stdout instead of stderr (default).")
170176

177+
171178
# The default built-in provider hosted under web/
172179
DEFAULT_VERSION_STRING = "comfyanonymous/ComfyUI@latest"
173180

comfy_api/feature_flags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
SERVER_FEATURE_FLAGS: Dict[str, Any] = {
1414
"supports_preview_metadata": True,
1515
"max_upload_size": args.max_upload_size * 1024 * 1024, # Convert MB to bytes
16+
"extension": {"manager": {"supports_v4": True}},
1617
}
1718

1819

main.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,31 @@
1515
from comfy_execution.utils import get_executing_context
1616
from comfy_api import feature_flags
1717

18+
1819
if __name__ == "__main__":
1920
#NOTE: These do not do anything on core ComfyUI, they are for custom nodes.
2021
os.environ['HF_HUB_DISABLE_TELEMETRY'] = '1'
2122
os.environ['DO_NOT_TRACK'] = '1'
2223

2324
setup_logger(log_level=args.verbose, use_stdout=args.log_stdout)
2425

26+
27+
def handle_comfyui_manager_unavailable():
28+
if not args.windows_standalone_build:
29+
logging.warning(f"\n\nYou appear to be running comfyui-manager from source, this is not recommended. Please install comfyui-manager using the following command:\ncommand:\n\t{sys.executable} -m pip install --pre comfyui_manager\n")
30+
args.enable_manager = False
31+
32+
33+
if args.enable_manager:
34+
if importlib.util.find_spec("comfyui_manager"):
35+
import comfyui_manager
36+
37+
if not comfyui_manager.__file__ or not comfyui_manager.__file__.endswith('__init__.py'):
38+
handle_comfyui_manager_unavailable()
39+
else:
40+
handle_comfyui_manager_unavailable()
41+
42+
2543
def apply_custom_paths():
2644
# extra model paths
2745
extra_model_paths_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extra_model_paths.yaml")
@@ -79,6 +97,11 @@ def execute_script(script_path):
7997

8098
for possible_module in possible_modules:
8199
module_path = os.path.join(custom_node_path, possible_module)
100+
101+
if args.enable_manager:
102+
if comfyui_manager.should_be_disabled(module_path):
103+
continue
104+
82105
if os.path.isfile(module_path) or module_path.endswith(".disabled") or module_path == "__pycache__":
83106
continue
84107

@@ -101,6 +124,10 @@ def execute_script(script_path):
101124
logging.info("")
102125

103126
apply_custom_paths()
127+
128+
if args.enable_manager:
129+
comfyui_manager.prestartup()
130+
104131
execute_prestartup_script()
105132

106133

@@ -323,6 +350,9 @@ def start_comfyui(asyncio_loop=None):
323350
asyncio.set_event_loop(asyncio_loop)
324351
prompt_server = server.PromptServer(asyncio_loop)
325352

353+
if args.enable_manager and not args.disable_manager_ui:
354+
comfyui_manager.start()
355+
326356
hook_breaker_ac10a0.save_functions()
327357
asyncio_loop.run_until_complete(nodes.init_extra_nodes(
328358
init_custom_nodes=(not args.disable_all_custom_nodes) or len(args.whitelist_custom_nodes) > 0,

manager_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
comfyui_manager==4.0.3b3

nodes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
import latent_preview
4444
import node_helpers
4545

46+
if args.enable_manager:
47+
import comfyui_manager
48+
4649
def before_node_execution():
4750
comfy.model_management.throw_exception_if_processing_interrupted()
4851

@@ -2243,6 +2246,12 @@ async def init_external_custom_nodes():
22432246
if args.disable_all_custom_nodes and possible_module not in args.whitelist_custom_nodes:
22442247
logging.info(f"Skipping {possible_module} due to disable_all_custom_nodes and whitelist_custom_nodes")
22452248
continue
2249+
2250+
if args.enable_manager:
2251+
if comfyui_manager.should_be_disabled(module_path):
2252+
logging.info(f"Blocked by policy: {module_path}")
2253+
continue
2254+
22462255
time_before = time.perf_counter()
22472256
success = await load_custom_node(module_path, base_node_names, module_parent="custom_nodes")
22482257
node_import_times.append((time.perf_counter() - time_before, module_path, success))

server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
# Import cache control middleware
4545
from middleware.cache_middleware import cache_control
4646

47+
if args.enable_manager:
48+
import comfyui_manager
49+
4750
async def send_socket_catch_exception(function, message):
4851
try:
4952
await function(message)
@@ -212,6 +215,9 @@ def __init__(self, loop):
212215
if args.disable_api_nodes:
213216
middlewares.append(create_block_external_middleware())
214217

218+
if args.enable_manager:
219+
middlewares.append(comfyui_manager.create_middleware())
220+
215221
max_upload_size = round(args.max_upload_size * 1024 * 1024)
216222
self.app = web.Application(client_max_size=max_upload_size, middlewares=middlewares)
217223
self.sockets = dict()
@@ -599,7 +605,7 @@ async def system_stats(request):
599605

600606
system_stats = {
601607
"system": {
602-
"os": os.name,
608+
"os": sys.platform,
603609
"ram_total": ram_total,
604610
"ram_free": ram_free,
605611
"comfyui_version": __version__,

0 commit comments

Comments
 (0)