-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathcm_cli_util.py
More file actions
72 lines (52 loc) · 2.04 KB
/
cm_cli_util.py
File metadata and controls
72 lines (52 loc) · 2.04 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
from __future__ import annotations
import os
import subprocess
import sys
import uuid
import typer
from rich import print
from comfy_cli.config_manager import ConfigManager
from comfy_cli.uv import DependencyCompiler
from comfy_cli.workspace_manager import WorkspaceManager
workspace_manager = WorkspaceManager()
# set of commands that invalidate (ie require an update of) dependencies after they are run
_dependency_cmds = {
"install",
"reinstall",
}
def execute_cm_cli(args, channel=None, fast_deps=False, mode=None) -> str | None:
_config_manager = ConfigManager()
workspace_path = workspace_manager.workspace_path
if not workspace_path:
print("\n[bold red]ComfyUI path is not resolved.[/bold red]\n", file=sys.stderr)
raise typer.Exit(code=1)
cmd = [sys.executable, '-m', 'comfyui_manager.cm_cli'] + args
if channel is not None:
cmd += ["--channel", channel]
if fast_deps:
cmd += ["--no-deps"]
if mode is not None:
cmd += ["--mode", mode]
new_env = os.environ.copy()
session_path = os.path.join(_config_manager.get_config_path(), "tmp", str(uuid.uuid4()))
new_env["__COMFY_CLI_SESSION__"] = session_path
new_env["COMFYUI_PATH"] = workspace_path
print(f"Execute from: {workspace_path}")
try:
result = subprocess.run(cmd, env=new_env, check=True, capture_output=True, text=True)
print(result.stdout)
if fast_deps and args[0] in _dependency_cmds:
# we're using the fast_deps behavior and just ran a command that invalidated the dependencies
depComp = DependencyCompiler(cwd=workspace_path)
depComp.compile_deps()
depComp.install_deps()
return result.stdout
except subprocess.CalledProcessError as e:
if e.returncode == 1:
print(f"\n[bold red]Execution error: {cmd}[/bold red]\n", file=sys.stderr)
return None
if e.returncode == 2:
return None
raise e
finally:
workspace_manager.set_recent_workspace(workspace_path)