From 9d2034bd4f307bff348e8e3ba4fcec8bb54ad77e Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Mon, 28 Apr 2025 00:13:31 +0900 Subject: [PATCH] fixed: crash related to deleted CNR node after installed modified: convert cm-cli.sh to cm-cli command --- cm-cli.sh | 2 - comfyui_manager/__init__.py | 4 +- comfyui_manager/cm_cli/__init__.py | 0 .../{cm-cli.py => cm_cli/__main__.py} | 48 ++++++++++++------- comfyui_manager/prestartup_script.py | 8 ++-- pyproject.toml | 5 +- 6 files changed, 43 insertions(+), 24 deletions(-) delete mode 100755 cm-cli.sh create mode 100644 comfyui_manager/cm_cli/__init__.py rename comfyui_manager/{cm-cli.py => cm_cli/__main__.py} (96%) diff --git a/cm-cli.sh b/cm-cli.sh deleted file mode 100755 index 1afaf926..00000000 --- a/cm-cli.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -python ./comfyui_manager/cm-cli.py $* diff --git a/comfyui_manager/__init__.py b/comfyui_manager/__init__.py index 38328c6a..9485ad84 100644 --- a/comfyui_manager/__init__.py +++ b/comfyui_manager/__init__.py @@ -1,6 +1,5 @@ import os import logging -from comfy.cli_args import args def prestartup(): from . import prestartup_script # noqa: F401 @@ -8,6 +7,8 @@ def prestartup(): def start(): + from comfy.cli_args import args + logging.info('[START] ComfyUI-Manager') from .common import cm_global # noqa: F401 @@ -32,6 +33,7 @@ def should_be_disabled(fullpath:str) -> bool: 1. Disables the legacy ComfyUI-Manager. 2. The blocklist can be expanded later based on policies. """ + from comfy.cli_args import args if not args.disable_manager: # In cases where installation is done via a zip archive, the directory name may not be comfyui-manager, and it may not contain a git repository. diff --git a/comfyui_manager/cm_cli/__init__.py b/comfyui_manager/cm_cli/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/comfyui_manager/cm-cli.py b/comfyui_manager/cm_cli/__main__.py similarity index 96% rename from comfyui_manager/cm-cli.py rename to comfyui_manager/cm_cli/__main__.py index 8dce67b9..eeb1bbac 100644 --- a/comfyui_manager/cm-cli.py +++ b/comfyui_manager/cm_cli/__main__.py @@ -15,7 +15,7 @@ import git import importlib -from .common import manager_util +from ..common import manager_util # read env vars # COMFYUI_FOLDERS_BASE_PATH is not required in cm-cli.py @@ -35,11 +35,11 @@ if not os.path.exists(os.path.join(comfy_path, 'folder_paths.py')): import utils.extra_config -from .common import cm_global -from .glob import manager_core as core -from .common import context -from .glob.manager_core import unified_manager -from .common import cnr_utils +from ..common import cm_global +from ..legacy import manager_core as core +from ..common import context +from ..legacy.manager_core import unified_manager +from ..common import cnr_utils comfyui_manager_path = os.path.abspath(os.path.dirname(__file__)) @@ -108,7 +108,7 @@ class Ctx: self.no_deps = False self.mode = 'cache' self.user_directory = None - self.custom_nodes_paths = [os.path.join(core.comfy_base_path, 'custom_nodes')] + self.custom_nodes_paths = [os.path.join(context.comfy_base_path, 'custom_nodes')] self.manager_files_directory = os.path.dirname(__file__) if Ctx.folder_paths is None: @@ -444,8 +444,11 @@ def show_list(kind, simple=False): flag = kind in ['all', 'cnr', 'installed', 'enabled'] for k, v in unified_manager.active_nodes.items(): if flag: - cnr = unified_manager.cnr_map[k] - processed[k] = "[ ENABLED ] ", cnr['name'], k, cnr['publisher']['name'], v[0] + cnr = unified_manager.cnr_map.get(k) + if cnr: + processed[k] = "[ ENABLED ] ", cnr['name'], k, cnr['publisher']['name'], v[0] + else: + processed[k] = None else: processed[k] = None @@ -465,8 +468,11 @@ def show_list(kind, simple=False): continue if flag: - cnr = unified_manager.cnr_map[k] - processed[k] = "[ DISABLED ] ", cnr['name'], k, cnr['publisher']['name'], ", ".join(list(v.keys())) + cnr = unified_manager.cnr_map.get(k) # NOTE: can this be None if removed from CNR after installed + if cnr: + processed[k] = "[ DISABLED ] ", cnr['name'], k, cnr['publisher']['name'], ", ".join(list(v.keys())) + else: + processed[k] = None else: processed[k] = None @@ -475,8 +481,11 @@ def show_list(kind, simple=False): continue if flag: - cnr = unified_manager.cnr_map[k] - processed[k] = "[ DISABLED ] ", cnr['name'], k, cnr['publisher']['name'], 'nightly' + cnr = unified_manager.cnr_map.get(k) + if cnr: + processed[k] = "[ DISABLED ] ", cnr['name'], k, cnr['publisher']['name'], 'nightly' + else: + processed[k] = None else: processed[k] = None @@ -496,9 +505,12 @@ def show_list(kind, simple=False): continue if flag: - cnr = unified_manager.cnr_map[k] - ver_spec = v['latest_version']['version'] if 'latest_version' in v else '0.0.0' - processed[k] = "[ NOT INSTALLED ] ", cnr['name'], k, cnr['publisher']['name'], ver_spec + cnr = unified_manager.cnr_map.get(k) + if cnr: + ver_spec = v['latest_version']['version'] if 'latest_version' in v else '0.0.0' + processed[k] = "[ NOT INSTALLED ] ", cnr['name'], k, cnr['publisher']['name'], ver_spec + else: + processed[k] = None else: processed[k] = None @@ -1286,6 +1298,10 @@ def export_custom_node_ids( print(f"{x['id']}@unknown", file=output_file) +def main(): + app() + + if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) sys.exit(app()) diff --git a/comfyui_manager/prestartup_script.py b/comfyui_manager/prestartup_script.py index 2ab0af2c..17b9a028 100644 --- a/comfyui_manager/prestartup_script.py +++ b/comfyui_manager/prestartup_script.py @@ -87,9 +87,6 @@ manager_pip_blacklist_path = os.path.join(manager_files_path, "pip_blacklist.lis restore_snapshot_path = os.path.join(manager_files_path, "startup-scripts", "restore-snapshot.json") manager_config_path = os.path.join(manager_files_path, 'config.ini') -cm_cli_path = os.path.join(comfyui_manager_path, "cm-cli.py") - - default_conf = {} def read_config(): @@ -563,7 +560,10 @@ if os.path.exists(restore_snapshot_path): if 'COMFYUI_FOLDERS_BASE_PATH' not in new_env: new_env["COMFYUI_FOLDERS_BASE_PATH"] = comfy_path - cmd_str = [sys.executable, cm_cli_path, 'restore-snapshot', restore_snapshot_path] + if 'COMFYUI_PATH' not in new_env: + new_env['COMFYUI_PATH'] = os.path.dirname(folder_paths.__file__) + + cmd_str = [sys.executable, '-m', 'comfyui_manager.cm_cli', 'restore-snapshot', restore_snapshot_path] exit_code = process_wrap(cmd_str, custom_nodes_base_path, handler=msg_capture, env=new_env) if exit_code != 0: diff --git a/pyproject.toml b/pyproject.toml index 568da858..8aa84345 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "comfyui-manager" license = { text = "GPL-3.0-only" } -version = "4.0.0-beta.2" +version = "4.0.0-beta.3" requires-python = ">= 3.9" description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI." readme = "README.md" @@ -48,6 +48,9 @@ Repository = "https://github.com/ltdrdata/ComfyUI-Manager" where = ["."] include = ["comfyui_manager*"] +[project.scripts] +cm-cli = "comfyui_manager.cm_cli.__main__:main" + [tool.ruff] line-length = 120 target-version = "py39"