Browse Source

implement package installation based on prestartup_script

pull/25/head
Dr.Lt.Data 1 year ago
parent
commit
3bda3f99f0
  1. 76
      __init__.py
  2. 10
      custom-node-list.json
  3. 14
      extension-node-map.json
  4. 8
      git_helper.py
  5. 37
      prestartup_script.py

76
__init__.py

@ -16,7 +16,9 @@ sys.path.append('../..')
from torchvision.datasets.utils import download_url
# ensure .js
print("### Loading: ComfyUI-Manager (V0.11.1)")
print("### Loading: ComfyUI-Manager (V0.12)")
comfy_ui_revision = "Unknown"
comfy_path = os.path.dirname(folder_paths.__file__)
custom_nodes_path = os.path.join(comfy_path, 'custom_nodes')
@ -29,19 +31,56 @@ local_db_custom_node_list = os.path.join(comfyui_manager_path, "custom-node-list
local_db_extension_node_mappings = os.path.join(comfyui_manager_path, "extension-node-map.json")
git_script_path = os.path.join(os.path.dirname(__file__), "git_helper.py")
startup_script_path = os.path.join(comfyui_manager_path, "startup-scripts")
def try_install_script(url, repo_path, install_cmd):
if platform.system() == "Windows" and comfy_ui_revision >= 1152:
if not os.path.exists(startup_script_path):
os.makedirs(startup_script_path)
script_path = os.path.join(startup_script_path, "install-scripts.txt")
with open(script_path, "a") as file:
obj = [repo_path] + install_cmd
file.write(f"{obj}\n")
return True
else:
code = subprocess.run(install_cmd, cwd=repo_path)
if platform.system() == "Windows":
try:
if int(comfy_ui_revision) < 1152:
print("\n\n###################################################################")
print(f"[WARN] ComfyUI-Manager: Your ComfyUI version ({comfy_ui_revision}) is too old. Please update to the latest version.")
print(f"[WARN] The extension installation feature may not work properly in the current installed ComfyUI version on Windows environment.")
print("###################################################################\n\n")
except:
pass
if code.returncode != 0:
print(f"install script failed: {url}")
return False
def print_comfyui_version():
global comfy_ui_revision
try:
repo = git.Repo(os.path.dirname(folder_paths.__file__))
revision_count = len(list(repo.iter_commits('HEAD')))
comfy_ui_revision = len(list(repo.iter_commits('HEAD')))
current_branch = repo.active_branch.name
git_hash = repo.head.commit.hexsha
try:
if int(comfy_ui_revision) < 1148:
print(f"\n\n## [WARN] ComfyUI-Manager: Your ComfyUI version ({comfy_ui_revision}) is too old. Please update to the latest version. ##\n\n")
except:
pass
if current_branch == "master":
print(f"### ComfyUI Revision: {revision_count} [{git_hash[:8]}]")
print(f"### ComfyUI Revision: {comfy_ui_revision} [{git_hash[:8]}]")
else:
print(f"### ComfyUI Revision: {revision_count} on '{current_branch}' [{git_hash[:8]}]")
print(f"### ComfyUI Revision: {comfy_ui_revision} on '{current_branch}' [{git_hash[:8]}]")
except:
print("### ComfyUI Revision: UNKNOWN (The currently installed ComfyUI is not a Git repository)")
@ -84,6 +123,10 @@ def git_repo_has_updates(path, do_fetch=False):
else:
# Fetch the latest commits from the remote repository
repo = git.Repo(path)
current_branch = repo.active_branch
branch_name = current_branch.name
remote_name = 'origin'
remote = repo.remote(name=remote_name)
@ -92,13 +135,13 @@ def git_repo_has_updates(path, do_fetch=False):
# Get the current commit hash and the commit hash of the remote branch
commit_hash = repo.head.commit.hexsha
remote_commit_hash = repo.refs[f'{remote_name}/HEAD'].object.hexsha
remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha
# Compare the commit hashes to determine if the local repository is behind the remote repository
if commit_hash != remote_commit_hash:
# Get the commit dates
commit_date = repo.head.commit.committed_datetime
remote_commit_date = repo.refs[f'{remote_name}/HEAD'].object.committed_datetime
remote_commit_date = repo.refs[f'{remote_name}/{branch_name}'].object.committed_datetime
# Compare the commit dates to determine if the local repository is behind the remote repository
if commit_date < remote_commit_date:
@ -153,9 +196,9 @@ def setup_js():
js_src_path = os.path.join(comfyui_manager_path, "js", "comfyui-manager.js")
shutil.copy(js_src_path, js_dest_path)
setup_js()
# Expand Server api
import server
@ -461,20 +504,12 @@ def execute_install_script(url, repo_path):
if os.path.exists(requirements_path):
print(f"Install: pip packages")
install_cmd = [sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]
code = subprocess.run(install_cmd, cwd=repo_path)
if code.returncode != 0:
print(f"install script failed: {url}")
return False
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"]
code = subprocess.run(install_cmd, cwd=repo_path)
if code.returncode != 0:
print(f"install script failed: {url}")
return False
try_install_script(url, repo_path, install_cmd)
return True
@ -711,14 +746,17 @@ async def install_custom_node(request):
# version check
repo = git.Repo(repo_path)
current_branch = repo.active_branch
branch_name = current_branch.name
remote_name = 'origin'
remote = repo.remote(name=remote_name)
remote.fetch()
commit_hash = repo.head.commit.hexsha
remote_commit_hash = repo.refs[f'{remote_name}/HEAD'].object.hexsha
remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha
print(f"{commit_hash} != {remote_commit_hash}")
if commit_hash != remote_commit_hash:
git_pull(repo_path)
execute_install_script("ComfyUI", repo_path)

10
custom-node-list.json

@ -627,6 +627,16 @@
"install_type": "git-clone",
"description": "NODES: CLIP Text Encode++. Achieve identical embeddings from stable-diffusion-webui for ComfyUI."
},
{
"author": "ZaneA",
"title": "ImageReward",
"reference": "https://github.com/ZaneA/ComfyUI-ImageReward",
"files": [
"https://github.com/ZaneA/ComfyUI-ImageReward"
],
"install_type": "git-clone",
"description": "NODES: ImageRewardLoader, ImageRewardScore"
},
{
"author": "taabata",
"title": "Syrian Falcon Nodes",

14
extension-node-map.json

@ -4,6 +4,8 @@
"Change Channel Count",
"Combine Masks",
"Constant Mask",
"Convert Color Space",
"Create QR Code",
"Create Rect Mask",
"Cut By Mask",
"Get Image Size",
@ -12,16 +14,20 @@
"Mask By Text",
"Mask Morphology",
"Mask To Region",
"MasqueradeIncrementer",
"Mix Color By Mask",
"Mix Images By Mask",
"Paste By Mask",
"Prune By Mask",
"Separate Mask Components",
"Unary Image Op",
"Unary Mask Op"
],
"https://github.com/BlenderNeko/ComfyUI_ADV_CLIP_emb": [
"BNK_AddCLIPSDXLParams",
"BNK_AddCLIPSDXLRParams",
"BNK_CLIPTextEncodeAdvanced",
"BNK_MixCLIPEmbeddings"
"BNK_CLIPTextEncodeSDXLAdvanced"
],
"https://github.com/BlenderNeko/ComfyUI_Cutoff": [
"BNK_CutoffBasePrompt",
@ -507,6 +513,7 @@
"Logic Boolean",
"Lora Loader",
"Mask Arbitrary Region",
"Mask Batch",
"Mask Batch to Mask",
"Mask Ceiling Region",
"Mask Crop Dominant Region",
@ -588,6 +595,10 @@
"https://github.com/YinBailiang/MergeBlockWeighted_fo_ComfyUI": [
"MergeBlockWeighted"
],
"https://github.com/ZaneA/ComfyUI-ImageReward": [
"ImageRewardLoader",
"ImageRewardScore"
],
"https://github.com/biegert/ComfyUI-CLIPSeg/raw/main/custom_nodes/clipseg.py": [
"CLIPSeg",
"CombineSegMasks"
@ -900,6 +911,7 @@
"https://github.com/taabata/Comfy_Syrian_Falcon_Nodes/raw/main/SyrianFalconNodes.py": [
"CompositeImage",
"KSamplerAdvancedCustom",
"LoopBack",
"QRGenerate",
"WordAsImage"
],

8
git_helper.py

@ -14,6 +14,10 @@ def gitclone(custom_nodes_path, url):
def gitcheck(path, do_fetch=False):
# Fetch the latest commits from the remote repository
repo = git.Repo(path)
current_branch = repo.active_branch
branch_name = current_branch.name
remote_name = 'origin'
remote = repo.remote(name=remote_name)
@ -22,13 +26,13 @@ def gitcheck(path, do_fetch=False):
# Get the current commit hash and the commit hash of the remote branch
commit_hash = repo.head.commit.hexsha
remote_commit_hash = repo.refs[f'{remote_name}/HEAD'].object.hexsha
remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha
# Compare the commit hashes to determine if the local repository is behind the remote repository
if commit_hash != remote_commit_hash:
# Get the commit dates
commit_date = repo.head.commit.committed_datetime
remote_commit_date = repo.refs[f'{remote_name}/HEAD'].object.committed_datetime
remote_commit_date = repo.refs[f'{remote_name}/{branch_name}'].object.committed_datetime
# Compare the commit dates to determine if the local repository is behind the remote repository
if commit_date < remote_commit_date:

37
prestartup_script.py

@ -0,0 +1,37 @@
import os
import subprocess
script_list_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "startup-scripts", "install-scripts.txt")
# Check if script_list_path exists
if os.path.exists(script_list_path):
print("\n#######################################################################")
print("[ComfyUI-Manager] Starting dependency installation for the extension\n")
executed = set()
# Read each line from the file and convert it to a list using eval
with open(script_list_path, 'r') as file:
for line in file:
if line in executed:
continue
executed.add(line)
try:
script = eval(line)
print(f"\n## Install dependency for '{script[0]}'")
code = subprocess.run(script[1:], cwd=script[0])
if code.returncode != 0:
print(f"install script failed: {script[0]}")
except Exception as e:
print(f"[ERROR] Failed to install: {line} / {e}")
# Remove the script_list_path file
if os.path.exists(script_list_path):
os.remove(script_list_path)
print("\n[ComfyUI-Manager] Dependency installation completed.")
print("#######################################################################\n")
Loading…
Cancel
Save