Browse Source

fix: apply requirements.txt and install.py when update_all

pull/180/head
Dr.Lt.Data 1 year ago
parent
commit
b3b8485fc6
  1. 47
      __init__.py
  2. 27
      prestartup_script.py

47
__init__.py

@ -14,7 +14,7 @@ import concurrent
import ssl import ssl
from urllib.parse import urlparse from urllib.parse import urlparse
version = "V1.0.2" version = "V1.1"
print(f"### Loading: ComfyUI-Manager ({version})") print(f"### Loading: ComfyUI-Manager ({version})")
@ -34,6 +34,10 @@ def handle_stream(stream, prefix):
def run_script(cmd, cwd='.'): def run_script(cmd, cwd='.'):
if len(cmd) > 0 and cmd[0].startswith("#"):
print(f"[ComfyUI-Manager] Unexpected behavior: `{cmd}`")
return 0
process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1) process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
stdout_thread = threading.Thread(target=handle_stream, args=(process.stdout, "")) stdout_thread = threading.Thread(target=handle_stream, args=(process.stdout, ""))
@ -233,6 +237,8 @@ def try_install_script(url, repo_path, install_cmd):
pass pass
if code != 0: if code != 0:
if url is None:
url = os.path.dirname(repo_path)
print(f"install script failed: {url}") print(f"install script failed: {url}")
return False return False
@ -325,7 +331,9 @@ def git_repo_has_updates(path, do_fetch=False, do_update=False):
raise ValueError('Not a git repository') raise ValueError('Not a git repository')
if platform.system() == "Windows": if platform.system() == "Windows":
return __win_check_git_update(path, do_fetch, do_update) res = __win_check_git_update(path, do_fetch, do_update)
execute_install_script(None, path, lazy_mode=True)
return res
else: else:
# Fetch the latest commits from the remote repository # Fetch the latest commits from the remote repository
repo = git.Repo(path) repo = git.Repo(path)
@ -349,6 +357,7 @@ def git_repo_has_updates(path, do_fetch=False, do_update=False):
new_commit_hash = repo.head.commit.hexsha new_commit_hash = repo.head.commit.hexsha
if commit_hash != new_commit_hash: if commit_hash != new_commit_hash:
execute_install_script(None, path)
print(f"\x1b[2K\rUpdated: {path}") print(f"\x1b[2K\rUpdated: {path}")
return True return True
else: else:
@ -958,24 +967,28 @@ def copy_set_active(files, is_disable, js_path_name='.'):
return True return True
def execute_install_script(url, repo_path): def execute_install_script(url, repo_path, lazy_mode=False):
install_script_path = os.path.join(repo_path, "install.py") install_script_path = os.path.join(repo_path, "install.py")
requirements_path = os.path.join(repo_path, "requirements.txt") requirements_path = os.path.join(repo_path, "requirements.txt")
if os.path.exists(requirements_path): if lazy_mode:
print("Install: pip packages") install_cmd = ["#LAZY-INSTALL-SCRIPT", sys.executable]
with open(requirements_path, "r") as requirements_file:
for line in requirements_file:
package_name = line.strip()
if package_name:
install_cmd = [sys.executable, "-m", "pip", "install", package_name]
if package_name.strip() != "":
try_install_script(url, repo_path, install_cmd)
if os.path.exists(install_script_path):
print(f"Install: install script")
install_cmd = [sys.executable, "install.py"]
try_install_script(url, repo_path, install_cmd) try_install_script(url, repo_path, install_cmd)
else:
if os.path.exists(requirements_path):
print("Install: pip packages")
with open(requirements_path, "r") as requirements_file:
for line in requirements_file:
package_name = line.strip()
if package_name:
install_cmd = [sys.executable, "-m", "pip", "install", package_name]
if package_name.strip() != "":
try_install_script(url, repo_path, install_cmd)
if os.path.exists(install_script_path):
print(f"Install: install script")
install_cmd = [sys.executable, "install.py"]
try_install_script(url, repo_path, install_cmd)
return True return True
@ -1163,7 +1176,7 @@ def gitclone_update(files):
repo_path = os.path.join(custom_nodes_path, repo_name) repo_path = os.path.join(custom_nodes_path, repo_name)
git_pull(repo_path) git_pull(repo_path)
if not execute_install_script(url, repo_path): if not execute_install_script(url, repo_path, lazy_mode=True):
return False return False
except Exception as e: except Exception as e:

27
prestartup_script.py

@ -252,6 +252,26 @@ if os.path.exists(restore_snapshot_path):
# Perform install # Perform install
script_list_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "startup-scripts", "install-scripts.txt") script_list_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "startup-scripts", "install-scripts.txt")
def execute_lazy_install_script(repo_path, executable):
install_script_path = os.path.join(repo_path, "install.py")
requirements_path = os.path.join(repo_path, "requirements.txt")
if os.path.exists(requirements_path):
print("Install: pip packages")
with open(requirements_path, "r") as requirements_file:
for line in requirements_file:
package_name = line.strip()
if package_name:
install_cmd = [sys.executable, "-m", "pip", "install", package_name]
process_wrap(install_cmd, repo_path)
if os.path.exists(install_script_path):
print(f"Install: install script")
install_cmd = [sys.executable, "install.py"]
process_wrap(install_cmd, repo_path)
# Check if script_list_path exists # Check if script_list_path exists
if os.path.exists(script_list_path): if os.path.exists(script_list_path):
print("\n#######################################################################") print("\n#######################################################################")
@ -268,7 +288,12 @@ if os.path.exists(script_list_path):
try: try:
script = eval(line) script = eval(line)
if os.path.exists(script[0]):
if script[1].startswith('#'):
if script[1] == "#LAZY-INSTALL-SCRIPT":
execute_lazy_install_script(script[0], script[2])
elif os.path.exists(script[0]):
print(f"\n## ComfyUI-Manager: EXECUTE => {script[1:]}") print(f"\n## ComfyUI-Manager: EXECUTE => {script[1:]}")
print(f"\n## Execute install/(de)activation script for '{script[0]}'") print(f"\n## Execute install/(de)activation script for '{script[0]}'")

Loading…
Cancel
Save