add support COMFYUI_FOLDERS_BASE_PATH

This commit is contained in:
Dr.Lt.Data 2025-01-26 18:01:34 +09:00
parent 3c64a8eb18
commit 41998565db
4 changed files with 43 additions and 22 deletions

View File

@ -20,12 +20,16 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "glob"))
import manager_util 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') comfy_path = os.environ.get('COMFYUI_PATH')
if comfy_path is None: if comfy_path is None:
try: try:
import folder_paths import folder_paths
comfy_path = os.path.join(os.path.dirname(folder_paths.__file__)) comfy_path = os.path.join(os.path.dirname(folder_paths.__file__))
except: 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, '..', '..')) comfy_path = os.path.abspath(os.path.join(manager_util.comfyui_manager_path, '..', '..'))
sys.path.append(comfy_path) sys.path.append(comfy_path)
@ -36,14 +40,7 @@ import manager_core as core
from manager_core import unified_manager from manager_core import unified_manager
import cnr_utils import cnr_utils
comfyui_manager_path = os.path.abspath(os.path.dirname(__file__)) 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_blacklist = ['torch', 'torchsde', 'torchvision']
cm_global.pip_downgrade_blacklist = ['torch', 'torchsde', 'torchvision', 'transformers', 'safetensors', 'kornia'] cm_global.pip_downgrade_blacklist = ['torch', 'torchsde', 'torchvision', 'transformers', 'safetensors', 'kornia']
@ -94,7 +91,7 @@ class Ctx:
self.no_deps = False self.no_deps = False
self.mode = 'cache' self.mode = 'cache'
self.user_directory = None 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__) self.manager_files_directory = os.path.dirname(__file__)
if Ctx.folder_paths is None: if Ctx.folder_paths is None:

View File

@ -41,7 +41,7 @@ import manager_downloader
from node_package import InstalledNodePackage 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 '') 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(): def get_script_env():
copied = os.environ.copy() new_env = os.environ.copy()
git_exe = get_config().get('git_exe') git_exe = get_config().get('git_exe')
if git_exe is not None: if git_exe is not None:
copied['GIT_EXE_PATH'] = git_exe new_env['GIT_EXE_PATH'] = git_exe
copied['COMFYUI_PATH'] = comfy_path
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 = {} invalid_nodes = {}
@ -112,7 +117,7 @@ def check_invalid_nodes():
sys.path.append(comfy_path) sys.path.append(comfy_path)
import folder_paths import folder_paths
except: except:
raise Exception(f"Invalid COMFYUI_PATH: {comfy_path}") raise Exception(f"Invalid COMFYUI_FOLDERS_BASE_PATH: {comfy_path}")
def check(root): def check(root):
global invalid_nodes global invalid_nodes
@ -147,7 +152,10 @@ def check_invalid_nodes():
print("\n---------------------------------------------------------------------------\n") print("\n---------------------------------------------------------------------------\n")
# read env vars
comfy_path = os.environ.get('COMFYUI_PATH') comfy_path = os.environ.get('COMFYUI_PATH')
comfy_base_path = os.environ.get('COMFYUI_FOLDERS_BASE_PATH')
if comfy_path is None: if comfy_path is None:
try: try:
import folder_paths import folder_paths
@ -155,6 +163,9 @@ if comfy_path is None:
except: except:
comfy_path = os.path.abspath(os.path.join(manager_util.comfyui_manager_path, '..', '..')) 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') 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") git_script_path = os.path.join(manager_util.comfyui_manager_path, "git_helper.py")
@ -1265,8 +1276,8 @@ class UnifiedManager:
remote.fetch() remote.fetch()
except Exception as e: except Exception as e:
if 'detected dubious' in str(e): if 'detected dubious' in str(e):
print("[ComfyUI-Manager] Try fixing 'dubious repository' error on 'ComfyUI' repository") print(f"[ComfyUI-Manager] Try fixing 'dubious repository' error on '{repo_path}' repository")
safedir_path = comfy_path.replace('\\', '/') safedir_path = repo_path.replace('\\', '/')
subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path]) subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path])
try: try:
remote.fetch() remote.fetch()
@ -2315,8 +2326,8 @@ def update_path(repo_path, instant_execution=False, no_deps=False):
remote.fetch() remote.fetch()
except Exception as e: except Exception as e:
if 'detected dubious' in str(e): if 'detected dubious' in str(e):
print("[ComfyUI-Manager] Try fixing 'dubious repository' error on 'ComfyUI' repository") print(f"[ComfyUI-Manager] Try fixing 'dubious repository' error on '{repo_path}' repository")
safedir_path = comfy_path.replace('\\', '/') safedir_path = repo_path.replace('\\', '/')
subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path]) subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path])
try: try:
remote.fetch() remote.fetch()

View File

@ -74,9 +74,18 @@ def check_file_logging():
check_file_logging() check_file_logging()
comfy_path = os.environ.get('COMFYUI_PATH') 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: if comfy_path is None:
comfy_path = os.path.abspath(os.path.dirname(sys.modules['__main__'].__file__)) 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_register_message_collapse = register_message_collapse
sys.__comfyui_manager_is_import_failed_extension = is_import_failed_extension sys.__comfyui_manager_is_import_failed_extension = is_import_failed_extension
cm_global.register_api('cm.register_message_collapse', register_message_collapse) 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 version:", sys.version)
print("** Python executable:", sys.executable) print("** Python executable:", sys.executable)
print("** ComfyUI Path:", comfy_path) print("** ComfyUI Path:", comfy_path)
print("** ComfyUI Base Folder Path:", comfy_base_path)
print("** User directory:", folder_paths.user_directory) print("** User directory:", folder_paths.user_directory)
print("** ComfyUI-Manager config path:", manager_config_path) print("** ComfyUI-Manager config path:", manager_config_path)
@ -558,7 +568,8 @@ if os.path.exists(restore_snapshot_path):
print("[ComfyUI-Manager] Restore snapshot.") print("[ComfyUI-Manager] Restore snapshot.")
new_env = os.environ.copy() 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] 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) 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"] install_cmd = [executable, "install.py"]
new_env = os.environ.copy() 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) 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]}'") print(f"\n## Execute install/(de)activation script for '{script[0]}'")
new_env = os.environ.copy() 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) exit_code = process_wrap(script[1:], script[0], env=new_env)
if exit_code != 0: if exit_code != 0:

View File

@ -1,7 +1,7 @@
[project] [project]
name = "comfyui-manager" 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." 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" } license = { file = "LICENSE.txt" }
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"] dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]