-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathinstall.py
More file actions
115 lines (91 loc) · 3.61 KB
/
install.py
File metadata and controls
115 lines (91 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import subprocess
from rich import print
import sys
import typer
from comfy_cli.command import custom_nodes
def install_comfyui_dependencies(repo_dir, torch_mode):
os.chdir(repo_dir)
# install torch
if torch_mode == "amd":
pip_url = ["--extra-index-url", "https://download.pytorch.org/whl/rocm6.0"]
else:
pip_url = ["--extra-index-url", "https://download.pytorch.org/whl/cu121"]
subprocess.run(
[sys.executable, "-m", "pip", "install", "torch", "torchvision", "torchaudio"]
+ pip_url
)
# install other requirements
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
# install requirements for manager
def install_manager_dependencies(repo_dir):
os.chdir(os.path.join(repo_dir, "custom_nodes", "ComfyUI-Manager"))
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
def execute(
url: str,
manager_url: str,
comfy_workspace: str,
restore: bool,
skip_manager: bool,
torch_mode=None,
commit=None,
*args,
**kwargs,
):
print(f"Installing from {url}")
# install ComfyUI
working_dir = os.path.expanduser(comfy_workspace)
repo_dir = os.path.join(working_dir, os.path.basename(url).replace(".git", ""))
repo_dir = os.path.abspath(repo_dir)
if os.path.exists(os.path.join(repo_dir, ".git")):
if restore or commit is not None:
if commit is not None:
os.chdir(repo_dir)
subprocess.run(["git", "checkout", commit])
install_comfyui_dependencies(repo_dir, torch_mode)
else:
print(
"ComfyUI is installed already. Skipping installation.\nIf you want to restore dependencies, add the '--restore' option."
)
else:
print("\nInstalling ComfyUI..")
os.makedirs(working_dir, exist_ok=True)
repo_dir = os.path.join(working_dir, os.path.basename(url).replace(".git", ""))
repo_dir = os.path.abspath(repo_dir)
subprocess.run(["git", "clone", url, repo_dir])
# checkout specified commit
if commit is not None:
os.chdir(repo_dir)
subprocess.run(["git", "checkout", commit])
install_comfyui_dependencies(repo_dir, torch_mode)
print("")
# install ComfyUI-Manager
if skip_manager:
print("Skipping installation of ComfyUI-Manager. (by --skip-manager)")
else:
manager_repo_dir = os.path.join(repo_dir, "custom_nodes", "ComfyUI-Manager")
if os.path.exists(manager_repo_dir):
if restore:
install_manager_dependencies(repo_dir)
else:
print(
f"Directory {manager_repo_dir} already exists. Skipping installation of ComfyUI-Manager.\nIf you want to restore dependencies, add the '--restore' option."
)
else:
print("\nInstalling ComfyUI-Manager..")
subprocess.run(["git", "clone", manager_url, manager_repo_dir])
install_manager_dependencies(repo_dir)
os.chdir(repo_dir)
print("")
def apply_snapshot(ctx: typer.Context, checker, filepath):
if not os.path.exists(filepath):
print(f"[bold red]File not found: {filepath}[/bold red]")
raise typer.Exit(code=1)
if checker.get_comfyui_manager_path() is not None and os.path.exists(
checker.get_comfyui_manager_path()
):
print(
f"[bold red]If ComfyUI-Manager is not installed, the snapshot feature cannot be used.[/bold red]"
)
raise typer.Exit(code=1)
custom_nodes.command.restore_snapshot(ctx, filepath)