73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
import os
|
|
import subprocess
|
|
import threading
|
|
import sys
|
|
import locale
|
|
import traceback
|
|
|
|
import os
|
|
import subprocess
|
|
import threading
|
|
import sys
|
|
import locale
|
|
import traceback
|
|
|
|
def handle_stream(stream, prefix):
|
|
stream.reconfigure(encoding=locale.getpreferredencoding(), errors='replace')
|
|
for msg in stream:
|
|
if prefix == '[!]' and ('it/s]' in msg or 's/it]' in msg) and ('%|' in msg or 'it [' in msg):
|
|
if msg.startswith('100%'):
|
|
print('\r' + msg, end="", file=sys.stderr),
|
|
else:
|
|
print('\r' + msg[:-1], end="", file=sys.stderr),
|
|
else:
|
|
if prefix == '[!]':
|
|
print(prefix, msg, end="", file=sys.stderr)
|
|
else:
|
|
print(prefix, msg, end="")
|
|
|
|
def run_script(cmd, cwd='.'):
|
|
if len(cmd) > 0 and cmd[0].startswith("#"):
|
|
print(f"[ComfyUI-Manager] Unexpected behavior: `{cmd}`")
|
|
return 0
|
|
|
|
process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
|
|
|
|
stdout_thread = threading.Thread(target=handle_stream, args=(process.stdout, ""))
|
|
stderr_thread = threading.Thread(target=handle_stream, args=(process.stderr, "[!]"))
|
|
|
|
stdout_thread.start()
|
|
stderr_thread.start()
|
|
|
|
stdout_thread.join()
|
|
stderr_thread.join()
|
|
|
|
return process.wait()
|
|
|
|
try:
|
|
from .nodes import NODE_CLASS_MAPPINGS
|
|
except:
|
|
my_path = os.path.dirname(__file__)
|
|
requirements_path = os.path.join(my_path, "requirements.txt")
|
|
|
|
print(f"## Dust3R: installing dependencies")
|
|
|
|
run_script([sys.executable, '-s', '-m', 'pip', 'install', '-r', requirements_path])
|
|
|
|
try:
|
|
from .nodes import NODE_CLASS_MAPPINGS
|
|
except:
|
|
print(f"## [ERROR] Dust3R: Attempting to reinstall dependencies using an alternative method.")
|
|
run_script([sys.executable, '-s', '-m', 'pip', 'install', '--user', '-r', requirements_path])
|
|
|
|
try:
|
|
from .nodes import NODE_CLASS_MAPPINGS
|
|
except:
|
|
print(f"## [ERROR] Dust3R: Failed to install package in the correct Python environment.")
|
|
traceback.print_exc()
|
|
|
|
print(f"## Dust3R: installing dependencies done.")
|
|
|
|
__all__ = ['NODE_CLASS_MAPPINGS']
|
|
|