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 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
from modules.model_loader import load_file_from_url
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_commit_hash = os.environ.get('COMFY_COMMIT_HASH', "2bc12d3d22efb5c63ae3a7fc342bb2dd16b31735")
commit = commit_hash()
tag = fooocus_tag
print(f"Python {sys.version}")
print(f"Version: {tag}")
print(f"Commit hash: {commit}")
comfyui_name = 'ComfyUI-from-StabilityAI-Official'
git_clone(comfy_repo, repo_dir(comfyui_name), "Inference Engine", comfy_commit_hash)

View File

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