This commit is contained in:
lvmin 2023-08-11 08:47:52 -07:00
parent 3260add223
commit 985d689861
2 changed files with 20 additions and 30 deletions

View File

@ -2,7 +2,7 @@ import os
import sys import sys
import platform import platform
from modules.launch_util import commit_hash, fooocus_tag, is_installed, run, python, \ from modules.launch_util import fooocus_tag, is_installed, run, python, \
run_pip, repo_dir, git_clone, requirements_met, script_path, dir_repos run_pip, repo_dir, git_clone, requirements_met, script_path, dir_repos
from modules.model_loader import load_file_from_url from modules.model_loader import load_file_from_url
from modules.path import modelfile_path, lorafile_path from modules.path import modelfile_path, lorafile_path
@ -21,12 +21,10 @@ def prepare_environment():
comfy_repo = os.environ.get('COMFY_REPO', "https://github.com/comfyanonymous/ComfyUI") comfy_repo = os.environ.get('COMFY_REPO', "https://github.com/comfyanonymous/ComfyUI")
comfy_commit_hash = os.environ.get('COMFY_COMMIT_HASH', "2bc12d3d22efb5c63ae3a7fc342bb2dd16b31735") comfy_commit_hash = os.environ.get('COMFY_COMMIT_HASH', "2bc12d3d22efb5c63ae3a7fc342bb2dd16b31735")
commit = commit_hash()
tag = fooocus_tag tag = fooocus_tag
print(f"Python {sys.version}") print(f"Python {sys.version}")
print(f"Version: {tag}") print(f"Version: {tag}")
print(f"Commit hash: {commit}")
comfyui_name = 'ComfyUI-from-StabilityAI-Official' comfyui_name = 'ComfyUI-from-StabilityAI-Official'
git_clone(comfy_repo, repo_dir(comfyui_name), "Inference Engine", comfy_commit_hash) git_clone(comfy_repo, repo_dir(comfyui_name), "Inference Engine", comfy_commit_hash)

View File

@ -1,18 +1,18 @@
import os import os
import importlib import importlib
import importlib.util import importlib.util
import shutil
import subprocess import subprocess
import sys import sys
import re import re
import logging import logging
import pygit2
from functools import lru_cache
logging.getLogger("torch.distributed.nn").setLevel(logging.ERROR) # sshh... logging.getLogger("torch.distributed.nn").setLevel(logging.ERROR) # sshh...
logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage()) logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage())
python = sys.executable python = sys.executable
git = os.environ.get('GIT', "git")
default_command_live = (os.environ.get('LAUNCH_LIVE_OUTPUT') == "1") default_command_live = (os.environ.get('LAUNCH_LIVE_OUTPUT') == "1")
index_url = os.environ.get('INDEX_URL', "") index_url = os.environ.get('INDEX_URL', "")
@ -23,35 +23,27 @@ dir_repos = "repositories"
fooocus_tag = '1.0.0' fooocus_tag = '1.0.0'
@lru_cache() def git_clone(url, dir, name, hash=None):
def commit_hash():
try: try:
return subprocess.check_output([git, "rev-parse", "HEAD"], shell=False, encoding='utf8').strip() try:
except Exception: repo = pygit2.Repository(dir)
return "<none>" print(f'{name} exists.')
except:
def git_clone(url, dir, name, commithash=None):
# TODO clone into temporary dir and move if successful
if os.path.exists(dir): if os.path.exists(dir):
if commithash is None: shutil.rmtree(dir, ignore_errors=True)
return os.makedirs(dir, exist_ok=True)
repo = pygit2.clone_repository(url, dir)
print(f'{name} cloned.')
current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, remote = repo.remotes['origin']
f"Couldn't determine {name}'s hash: {commithash}", live=False).strip() remote.fetch()
if current_hash == commithash:
return
run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}") commit = repo.get(hash)
run(f'"{git}" -C "{dir}" checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...",
f"Couldn't checkout commit {commithash} for {name}", live=True)
return
run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}", live=True) repo.checkout_tree(commit, strategy=pygit2.GIT_CHECKOUT_FORCE)
print(f'{name} checkout finished.')
if commithash is not None: except Exception as e:
run(f'"{git}" -C "{dir}" checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}") print(f'Git clone failed for {name}: {str(e)}')
def repo_dir(name): def repo_dir(name):