diff --git a/cm-cli.py b/cm-cli.py index c85599ea..2a045bd1 100644 --- a/cm-cli.py +++ b/cm-cli.py @@ -20,12 +20,16 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "glob")) import manager_util +# read env vars +# COMFYUI_FOLDERS_BASE_PATH is not required in cm-cli.py +# `comfy_path` should be resolved before importing manager_core comfy_path = os.environ.get('COMFYUI_PATH') if comfy_path is None: try: import folder_paths comfy_path = os.path.join(os.path.dirname(folder_paths.__file__)) except: + print("\n[bold yellow]WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `custom_nodes/ComfyUI-Manager/../../` as the ComfyUI path.[/bold yellow]", file=sys.stderr) comfy_path = os.path.abspath(os.path.join(manager_util.comfyui_manager_path, '..', '..')) sys.path.append(comfy_path) @@ -36,14 +40,7 @@ import manager_core as core from manager_core import unified_manager import cnr_utils - comfyui_manager_path = os.path.abspath(os.path.dirname(__file__)) -comfy_path = os.environ.get('COMFYUI_PATH') - -if comfy_path is None: - print("\n[bold yellow]WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `custom_nodes/ComfyUI-Manager/../../` as the ComfyUI path.[/bold yellow]", file=sys.stderr) - comfy_path = os.path.abspath(os.path.join(comfyui_manager_path, '..', '..')) - cm_global.pip_blacklist = ['torch', 'torchsde', 'torchvision'] cm_global.pip_downgrade_blacklist = ['torch', 'torchsde', 'torchvision', 'transformers', 'safetensors', 'kornia'] @@ -94,7 +91,7 @@ class Ctx: self.no_deps = False self.mode = 'cache' self.user_directory = None - self.custom_nodes_paths = [os.path.join(core.comfy_path, 'custom_nodes')] + self.custom_nodes_paths = [os.path.join(core.comfy_base_path, 'custom_nodes')] self.manager_files_directory = os.path.dirname(__file__) if Ctx.folder_paths is None: diff --git a/glob/manager_core.py b/glob/manager_core.py index 5e07d7bb..8a8a3663 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -41,7 +41,7 @@ import manager_downloader from node_package import InstalledNodePackage -version_code = [3, 9, 2] +version_code = [3, 9, 3] version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') @@ -81,13 +81,18 @@ def get_comfyui_tag(): def get_script_env(): - copied = os.environ.copy() + new_env = os.environ.copy() git_exe = get_config().get('git_exe') if git_exe is not None: - copied['GIT_EXE_PATH'] = git_exe - copied['COMFYUI_PATH'] = comfy_path + new_env['GIT_EXE_PATH'] = git_exe - return copied + if 'COMFYUI_PATH' not in new_env: + new_env['COMFYUI_PATH'] = comfy_path + + if 'COMFYUI_FOLDERS_BASE_PATH' not in new_env: + new_env['COMFYUI_FOLDERS_BASE_PATH'] = comfy_path + + return new_env invalid_nodes = {} @@ -112,7 +117,7 @@ def check_invalid_nodes(): sys.path.append(comfy_path) import folder_paths except: - raise Exception(f"Invalid COMFYUI_PATH: {comfy_path}") + raise Exception(f"Invalid COMFYUI_FOLDERS_BASE_PATH: {comfy_path}") def check(root): global invalid_nodes @@ -147,7 +152,10 @@ def check_invalid_nodes(): print("\n---------------------------------------------------------------------------\n") +# read env vars comfy_path = os.environ.get('COMFYUI_PATH') +comfy_base_path = os.environ.get('COMFYUI_FOLDERS_BASE_PATH') + if comfy_path is None: try: import folder_paths @@ -155,6 +163,9 @@ if comfy_path is None: except: comfy_path = os.path.abspath(os.path.join(manager_util.comfyui_manager_path, '..', '..')) +if comfy_base_path is None: + comfy_base_path = comfy_path + channel_list_template_path = os.path.join(manager_util.comfyui_manager_path, 'channels.list.template') git_script_path = os.path.join(manager_util.comfyui_manager_path, "git_helper.py") @@ -1265,8 +1276,8 @@ class UnifiedManager: remote.fetch() except Exception as e: if 'detected dubious' in str(e): - print("[ComfyUI-Manager] Try fixing 'dubious repository' error on 'ComfyUI' repository") - safedir_path = comfy_path.replace('\\', '/') + print(f"[ComfyUI-Manager] Try fixing 'dubious repository' error on '{repo_path}' repository") + safedir_path = repo_path.replace('\\', '/') subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path]) try: remote.fetch() @@ -2315,8 +2326,8 @@ def update_path(repo_path, instant_execution=False, no_deps=False): remote.fetch() except Exception as e: if 'detected dubious' in str(e): - print("[ComfyUI-Manager] Try fixing 'dubious repository' error on 'ComfyUI' repository") - safedir_path = comfy_path.replace('\\', '/') + print(f"[ComfyUI-Manager] Try fixing 'dubious repository' error on '{repo_path}' repository") + safedir_path = repo_path.replace('\\', '/') subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path]) try: remote.fetch() diff --git a/prestartup_script.py b/prestartup_script.py index 249eeb9b..1fd1cab9 100644 --- a/prestartup_script.py +++ b/prestartup_script.py @@ -74,9 +74,18 @@ def check_file_logging(): check_file_logging() comfy_path = os.environ.get('COMFYUI_PATH') +comfy_base_path = os.environ.get('COMFYUI_FOLDERS_BASE_PATH') + +if comfy_path is None: + # legacy env var + comfy_path = os.environ.get('COMFYUI_PATH') + if comfy_path is None: comfy_path = os.path.abspath(os.path.dirname(sys.modules['__main__'].__file__)) +if comfy_base_path is None: + comfy_base_path = comfy_path + sys.__comfyui_manager_register_message_collapse = register_message_collapse sys.__comfyui_manager_is_import_failed_extension = is_import_failed_extension cm_global.register_api('cm.register_message_collapse', register_message_collapse) @@ -427,6 +436,7 @@ print("** Platform:", platform.system()) print("** Python version:", sys.version) print("** Python executable:", sys.executable) print("** ComfyUI Path:", comfy_path) +print("** ComfyUI Base Folder Path:", comfy_base_path) print("** User directory:", folder_paths.user_directory) print("** ComfyUI-Manager config path:", manager_config_path) @@ -558,7 +568,8 @@ if os.path.exists(restore_snapshot_path): print("[ComfyUI-Manager] Restore snapshot.") new_env = os.environ.copy() - new_env["COMFYUI_PATH"] = comfy_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] exit_code = process_wrap(cmd_str, custom_nodes_base_path, handler=msg_capture, env=new_env) @@ -601,7 +612,8 @@ def execute_lazy_install_script(repo_path, executable): install_cmd = [executable, "install.py"] new_env = os.environ.copy() - new_env["COMFYUI_PATH"] = comfy_path + if 'COMFYUI_FOLDERS_BASE_PATH' not in new_env: + new_env["COMFYUI_FOLDERS_BASE_PATH"] = comfy_path process_wrap(install_cmd, repo_path, env=new_env) @@ -703,7 +715,8 @@ if os.path.exists(script_list_path): print(f"\n## Execute install/(de)activation script for '{script[0]}'") new_env = os.environ.copy() - new_env["COMFYUI_PATH"] = comfy_path + if 'COMFYUI_FOLDERS_BASE_PATH' not in new_env: + new_env["COMFYUI_FOLDERS_BASE_PATH"] = comfy_path exit_code = process_wrap(script[1:], script[0], env=new_env) if exit_code != 0: diff --git a/pyproject.toml b/pyproject.toml index c7a28940..ec5f7318 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-manager" description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI." -version = "3.9.2" +version = "3.9.3" license = { file = "LICENSE.txt" } dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]