Skip to content

Commit

Permalink
provide COMFYUI_PATH environment variable when executing install.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdrdata committed Jun 27, 2024
1 parent 53159fe commit 6765598
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
23 changes: 17 additions & 6 deletions glob/manager_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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()


Expand Down
28 changes: 22 additions & 6 deletions prestartup_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import ast


glob_path = os.path.join(os.path.dirname(__file__), "glob")
sys.path.append(glob_path)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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:
Expand All @@ -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.")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down

0 comments on commit 6765598

Please sign in to comment.