Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Akegarasu committed Oct 5, 2024
1 parent e0dd4d5 commit aa3cba0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
6 changes: 4 additions & 2 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import sys

from mikazuki.launch_utils import (base_dir_path, catch_exception,
from mikazuki.launch_utils import (base_dir_path, catch_exception, git_tag,
prepare_environment, check_port_avaliable, find_avaliable_ports)
from mikazuki.log import log

Expand Down Expand Up @@ -53,7 +53,7 @@ def run_tag_editor():
def launch():
log.info("Starting SD-Trainer Mikazuki GUI...")
log.info(f"Base directory: {base_dir_path()}, Working directory: {os.getcwd()}")
log.info(f'{platform.system()} Python {platform.python_version()} {sys.executable}')
log.info(f"{platform.system()} Python {platform.python_version()} {sys.executable}")

if not args.skip_prepare_environment:
prepare_environment(disable_auto_mirror=args.disable_auto_mirror, skip_prepare_onnxruntime=args.skip_prepare_onnxruntime)
Expand All @@ -65,6 +65,8 @@ def launch():
else:
log.error("port finding fallback error")

log.info(f"SD-Trainer Version: {git_tag(base_dir_path())}")

os.environ["MIKAZUKI_HOST"] = args.host
os.environ["MIKAZUKI_PORT"] = str(args.port)
os.environ["MIKAZUKI_TENSORBOARD_HOST"] = args.tensorboard_host
Expand Down
43 changes: 31 additions & 12 deletions mikazuki/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,53 @@ def base_dir_path():


def find_windows_git():
possible_paths = ["git\\bin\\git.exe", "git\\cmd\\git.exe", "Git\\mingw64\\libexec\\git-core\\git.exe"]
possible_paths = ["git\\bin\\git.exe", "git\\cmd\\git.exe", "Git\\mingw64\\libexec\\git-core\\git.exe", "C:\\Program Files\\Git\\cmd\\git.exe"]
for path in possible_paths:
if os.path.exists(path):
return path


def prepare_git():
if shutil.which("git"):
return True

log.info("Finding git...")

if sys.platform == "win32":
git_path = find_windows_git()

if git_path is not None:
log.info(f"Git not found, but found git in {git_path}, add it to PATH")
os.environ["PATH"] += os.pathsep + os.path.dirname(git_path)
return True
else:
return False
else:
log.error("git not found, please install git first")
return False


def prepare_submodules():
frontend_path = base_dir_path() / "frontend" / "dist"
tag_editor_path = base_dir_path() / "mikazuki" / "dataset-tag-editor" / "scripts"

if not os.path.exists(frontend_path) or not os.path.exists(tag_editor_path):
log.info("submodule not found, try clone...")
log.info("checking git installation...")
if not shutil.which("git"):
if sys.platform == "win32":
git_path = find_windows_git()

if git_path is not None:
log.info(f"Git not found, but found git in {git_path}, add it to PATH")
os.environ["PATH"] += os.pathsep + os.path.dirname(git_path)
return
else:
log.error("git not found, please install git first")
sys.exit(1)
if not prepare_git():
log.error("git not found, please install git first")
sys.exit(1)
subprocess.run(["git", "submodule", "init"])
subprocess.run(["git", "submodule", "update"])


def git_tag(path: str) -> str:
try:
return subprocess.check_output(["git", "-C", path, "describe", "--tags"]).strip().decode("utf-8")
except Exception as e:
return "<none>"


def check_dirs(dirs: List):
for d in dirs:
if not os.path.exists(d):
Expand Down

0 comments on commit aa3cba0

Please sign in to comment.