diff --git a/glob/manager_core.py b/glob/manager_core.py index 3d204393..ba3059aa 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -23,12 +23,17 @@ import cm_global from manager_util import * -version = [2, 42] +version = [2, 43] version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '') + comfyui_manager_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) custom_nodes_path = os.path.abspath(os.path.join(comfyui_manager_path, '..')) -comfy_path = os.path.abspath(os.path.join(custom_nodes_path, '..')) + +comfy_path = os.environ.get('COMFYUI_PATH') +if comfy_path is None: + comfy_path = os.path.abspath(os.path.join(custom_nodes_path, '..')) + channel_list_path = os.path.join(comfyui_manager_path, 'channels.list') config_path = os.path.join(comfyui_manager_path, "config.ini") startup_script_path = os.path.join(comfyui_manager_path, "startup-scripts") @@ -181,7 +186,9 @@ def run_script(self, cmd, cwd='.'): print(f"[ComfyUI-Manager] Unexpected behavior: `{cmd}`") return 0 - subprocess.check_call(cmd, cwd=cwd) + new_env = os.environ.copy() + new_env["COMFYUI_PATH"] = comfy_path + subprocess.check_call(cmd, cwd=cwd, env=new_env) return 0 @@ -325,6 +332,8 @@ def __win_check_git_update(path, do_fetch=False, do_update=False): else: command = [sys.executable, git_script_path, "--check", path] + new_env = os.environ.copy() + new_env["COMFYUI_PATH"] = comfy_path process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=custom_nodes_path) output, _ = process.communicate() output = output.decode('utf-8').strip() @@ -334,10 +343,10 @@ def __win_check_git_update(path, do_fetch=False, do_update=False): safedir_path = path.replace('\\', '/') try: print(f"[ComfyUI-Manager] Try fixing 'dubious repository' error on '{safedir_path}' repo") - process = subprocess.Popen(['git', 'config', '--global', '--add', 'safe.directory', safedir_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(['git', 'config', '--global', '--add', 'safe.directory', safedir_path], env=new_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, _ = process.communicate() - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(command, env=new_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, _ = process.communicate() output = output.decode('utf-8').strip() except Exception: @@ -376,8 +385,10 @@ def __win_check_git_update(path, do_fetch=False, do_update=False): def __win_check_git_pull(path): + new_env = os.environ.copy() + new_env["COMFYUI_PATH"] = comfy_path command = [sys.executable, git_script_path, "--pull", path] - process = subprocess.Popen(command, cwd=custom_nodes_path) + process = subprocess.Popen(command, env=new_env, cwd=custom_nodes_path) process.wait() diff --git a/prestartup_script.py b/prestartup_script.py index 47945f33..bfc31c04 100644 --- a/prestartup_script.py +++ b/prestartup_script.py @@ -10,6 +10,7 @@ import json import ast + glob_path = os.path.join(os.path.dirname(__file__), "glob") sys.path.append(glob_path) @@ -59,6 +60,9 @@ def check_file_logging(): check_file_logging() +comfy_path = os.environ.get('COMFYUI_PATH') +if comfy_path is None: + comfy_path = os.path.abspath(sys.modules['__main__'].__file__) sys.__comfyui_manager_register_message_collapse = register_message_collapse sys.__comfyui_manager_is_import_failed_extension = is_import_failed_extension @@ -137,8 +141,8 @@ def handle_stream(stream, prefix): print(prefix, msg, end="") -def process_wrap(cmd_str, cwd_path, handler=None): - process = subprocess.Popen(cmd_str, cwd=cwd_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1) +def process_wrap(cmd_str, cwd_path, handler=None, env=None): + process = subprocess.Popen(cmd_str, cwd=cwd_path, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1) if handler is None: handler = handle_stream @@ -333,6 +337,7 @@ def close_log(): print("** Platform:", platform.system()) print("** Python version:", sys.version) print("** Python executable:", sys.executable) +print("** ComfyUI Path:", comfy_path) if enable_file_logging: print("** Log path:", os.path.abspath('comfyui.log')) @@ -475,7 +480,10 @@ def msg_capture(stream, prefix): print(f"[ComfyUI-Manager] Restore snapshot.") cmd_str = [sys.executable, git_script_path, '--apply-snapshot', restore_snapshot_path] - exit_code = process_wrap(cmd_str, custom_nodes_path, handler=msg_capture) + + new_env = os.environ.copy() + new_env["COMFYUI_PATH"] = comfy_path + exit_code = process_wrap(cmd_str, custom_nodes_path, handler=msg_capture, env=new_env) repository_name = '' for url in cloned_repos: @@ -502,7 +510,10 @@ def msg_capture(stream, prefix): processed_install.add(f'{repo_path}/install.py') install_cmd = [sys.executable, install_script_path] print(f">>> {install_cmd} / {repo_path}") - this_exit_code += process_wrap(install_cmd, repo_path) + + new_env = os.environ.copy() + new_env["COMFYUI_PATH"] = comfy_path + this_exit_code += process_wrap(install_cmd, repo_path, env=new_env) if this_exit_code != 0: print(f"[ComfyUI-Manager] Restoring '{repository_name}' is failed.") @@ -542,7 +553,10 @@ def execute_lazy_install_script(repo_path, executable): processed_install.add(f'{repo_path}/install.py') print(f"Install: install script for '{repo_path}'") install_cmd = [executable, "install.py"] - process_wrap(install_cmd, repo_path) + + new_env = os.environ.copy() + new_env["COMFYUI_PATH"] = comfy_path + process_wrap(install_cmd, repo_path, env=new_env) # Check if script_list_path exists @@ -576,7 +590,9 @@ def execute_lazy_install_script(repo_path, executable): print(f"\n## ComfyUI-Manager: EXECUTE => {script[1:]}") print(f"\n## Execute install/(de)activation script for '{script[0]}'") - exit_code = process_wrap(script[1:], script[0]) + new_env = os.environ.copy() + new_env["COMFYUI_PATH"] = comfy_path + exit_code = process_wrap(script[1:], script[0], env=new_env) if exit_code != 0: print(f"install/(de)activation script failed: {script[0]}") diff --git a/pyproject.toml b/pyproject.toml index 9e28c08b..7adf76af 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 = "2.42" +version = "2.43" license = "LICENSE" dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]