-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.py
78 lines (65 loc) · 2.15 KB
/
install.py
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
import subprocess
import sys
import os
import git
import shutil
from tqdm.auto import tqdm
from git.remote import RemoteProgress
if sys.platform.startswith("win"):
raise OSError("Onediff does not support Windows systems. "
"Please use WSL2: https://github.com/siliconflow/onediff/wiki")
class GitProgress(RemoteProgress):
def __init__(self):
super().__init__()
self.pbar = tqdm()
def update(self, op_code, cur_count, max_count=None, message=''):
self.pbar.total = max_count
self.pbar.n = cur_count
self.pbar.pos = 0
self.pbar.refresh()
command = [
"python3",
"-m",
"pip",
"install",
"--pre",
"oneflow",
"-f",
"https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu118"
]
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
while True:
output = process.stdout.readline()
error = process.stderr.readline()
if output == '' and error == '' and process.poll() is not None:
break
if output:
print(output.strip())
if error:
print(error.strip(), file=sys.stderr)
return_code = process.poll()
if return_code != 0:
raise RuntimeError(f"Installation failed with return code {return_code}")
else:
print("Installation successful")
onediff_url = "https://github.com/siliconflow/onediff"
comfy_path = os.environ.get('COMFYUI_PATH')
custom_nodes_path = os.path.join(comfy_path, 'custom_nodes')
repo_path = os.path.join(custom_nodes_path, "onediff")
print(f"Download: git clone '{onediff_url}'")
repo = git.Repo.clone_from(onediff_url, repo_path, recursive=True, progress=GitProgress())
repo.git.clear_cache()
repo.close()
onediff_path = os.path.join(custom_nodes_path, "onediff")
old_onediff_comfy_nodes_path = os.path.join(custom_nodes_path, "onediff_comfy_nodes")
new_onediff_comfy_nodes_path = os.path.join(onediff_path, "onediff_comfy_nodes")
shutil.move(os.path.abspath(__file__), onediff_path)
shutil.rmtree(old_onediff_comfy_nodes_path)
shutil.move(new_onediff_comfy_nodes_path, custom_nodes_path)
shutil.rmtree(onediff_path)
print("Onediff comfy nodes are ready.")