Skip to content

Commit 72b1d92

Browse files
committed
Misc changes function
- Disable config writing for now: need to coordinate with @DaTa to find a viable place to write config file - Rename from `nodes` to `node` and `models` to `model` - Refactor to call main function from cmdline.py so init() can get called every time.
1 parent 2b2eee3 commit 72b1d92

File tree

9 files changed

+112
-45
lines changed

9 files changed

+112
-45
lines changed

DEV_README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ This guide provides an overview of how to develop in this repository.
1515

1616
`comfy --help`
1717

18-
4. Add more commands (follow the [Add New Command](#add-new-command) guide)
18+
<!-- 4. Add more commands (follow the [Add New Command](#add-new-command) guide)
1919
20-
pip install .
20+
pip install . -->
2121

2222
## Add New Command
2323

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,42 @@ comfy provides a convenient way to manage custom nodes for extending ComfyUI's f
8181

8282
- Show custom nodes' information:
8383
```
84-
comfy nodes [show|simple-show] [installed|enabled|not-installed|disabled|all|snapshot|snapshot-list]
84+
comfy node [show|simple-show] [installed|enabled|not-installed|disabled|all|snapshot|snapshot-list]
8585
?[--channel <channel name>]
8686
?[--mode [remote|local|cache]]
8787
```
8888
-
89-
`comfy nodes show all --channel recent`
89+
`comfy node show all --channel recent`
9090

91-
`comfy nodes simple-show installed`
91+
`comfy node simple-show installed`
9292

93-
`comfy nodes update all`
93+
`comfy node update all`
9494

95-
`comfy nodes install ComfyUI-Impact-Pack`
95+
`comfy node install ComfyUI-Impact-Pack`
9696

9797

9898
- Managing snapshot:
9999

100-
`comfy nodes save-snapshot`
100+
`comfy node save-snapshot`
101101

102-
`comfy nodes restore-snapshot <snapshot name>`
102+
`comfy node restore-snapshot <snapshot name>`
103+
104+
105+
### Managing Models
106+
107+
- Model downloading
108+
109+
`comfy model get`
110+
111+
*Downloading models that have already been installed will
112+
113+
- Model remove
114+
115+
`comfy model enable-gui`
116+
117+
- Model list
118+
119+
`comfy model list`
103120

104121

105122
### Managing ComfyUI-Manager

comfy_cli/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from comfy_cli.cmdline import init, app
1+
from comfy_cli.cmdline import main
22

33
if __name__ == '__main__': # pragma: nocover
4-
init()
5-
app()
4+
main()

comfy_cli/cmdline.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import typer
44
from typing_extensions import Annotated
5-
from comfy_cli.command.models import models
5+
from comfy_cli.command.models import models as models_command
66
from rich import print
77
import os
88
import subprocess
@@ -21,13 +21,17 @@
2121
app = typer.Typer()
2222

2323

24+
def main():
25+
init()
26+
app()
27+
2428
def init():
25-
_env_checker = EnvChecker()
29+
# TODO(yoland): after this
2630
metadata_manager = MetadataManager()
2731
start_time = time.time()
2832
metadata_manager.scan_dir()
2933
end_time = time.time()
30-
34+
3135
print(f"scan_dir took {end_time - start_time:.2f} seconds to run")
3236

3337

@@ -53,7 +57,7 @@ def install(
5357
typer.Option(
5458
show_default=False,
5559
help="Path to ComfyUI workspace")
56-
] = constants.COMFY_WORKSPACE,
60+
] = "~/comfy",
5761
skip_manager: Annotated[
5862
bool,
5963
lambda: typer.Option(
@@ -87,10 +91,11 @@ def install(
8791

8892

8993
def update(self):
94+
_env_checker = EnvChecker()
9095
print(f"Updating ComfyUI in {self.workspace}...")
9196
os.chdir(self.workspace)
92-
subprocess.run(["git", "pull"])
93-
subprocess.run(["pip", "install", "-r", "requirements.txt"])
97+
subprocess.run(["git", "pull"], check=True)
98+
subprocess.run(["pip", "install", "-r", "requirements.txt"], check=True)
9499

95100

96101
@app.command(help="Run workflow file")
@@ -101,8 +106,13 @@ def run(
101106

102107

103108
def launch_comfyui(_env_checker, cpu):
104-
_env_checker.config['DEFAULT']['recent_path'] = os.getcwd()
105-
_env_checker.write_config()
109+
# TODO(yoland/data): Disabled config writing for now, checking with @data
110+
# We need to find a viable place to write config file, e.g. standard place
111+
# for macOS: ~/Library/Application Support/
112+
# for linx: ~/.config/
113+
# for windows: C:\Users\<username>\AppData\Local\
114+
#_env_checker.config['DEFAULT']['recent_path'] = os.getcwd()
115+
#_env_checker.write_config()
106116

107117
env_path = _env_checker.get_isolated_env()
108118
reboot_path = None
@@ -115,9 +125,9 @@ def launch_comfyui(_env_checker, cpu):
115125

116126
while True:
117127
if cpu:
118-
subprocess.run([sys.executable, "main.py", "--cpu"], env=new_env)
128+
subprocess.run([sys.executable, "main.py", "--cpu"], env=new_env, check=False)
119129
else:
120-
subprocess.run([sys.executable, "main.py"], env=new_env)
130+
subprocess.run([sys.executable, "main.py"], env=new_env, check=False)
121131

122132
if not os.path.exists(reboot_path):
123133
return
@@ -158,7 +168,7 @@ def launch(workspace: Annotated[
158168
os.chdir(comfy_path)
159169
launch_comfyui(_env_checker, cpu)
160170
else:
161-
print(f"\nComfyUI is not available.\n", file=sys.stderr)
171+
print("\nComfyUI is not available.\nTo install ComfyUI, you can run:\n\n\tcomfy install\n\n", file=sys.stderr)
162172
raise typer.Exit(code=1)
163173

164174

@@ -168,6 +178,14 @@ def env():
168178
_env_checker.print()
169179

170180

171-
app.add_typer(models.app, name="models", help="Manage models.")
172-
app.add_typer(custom_nodes.app, name="nodes", help="Manage custom nodes.")
173-
app.add_typer(custom_nodes.manager_app, name="manager", help="Manager ComfyUI-Manager.")
181+
@app.command(hidden=True)
182+
def nodes():
183+
print("\n[bold red] No such command, did you mean 'comfy node' instead?[/bold red]\n")
184+
185+
@app.command(hidden=True)
186+
def models():
187+
print("\n[bold red] No such command, did you mean 'comfy model' instead?[/bold red]\n")
188+
189+
app.add_typer(models_command.app, name="model", help="Manage models.")
190+
app.add_typer(custom_nodes.app, name="node", help="Manage custom nodes.")
191+
app.add_typer(custom_nodes.manager_app, name="manager", help="Manager ComfyUI-Manager.")

comfy_cli/command/custom_nodes/command.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111

1212
def execute_cm_cli(args, channel=None, mode=None, workspace=None):
13+
# TODO(yoland/data): Disabled config writing for now, checking with @data
14+
# We need to find a viable place to write config file, e.g. standard place
15+
# for macOS: ~/Library/Application Support/
16+
# for linx: ~/.config/
17+
# for windows: C:\Users\<username>\AppData\Local\
1318
_env_checker = EnvChecker()
1419
_env_checker.write_config()
1520

@@ -48,7 +53,7 @@ def execute_cm_cli(args, channel=None, mode=None, workspace=None):
4853
subprocess.run(cmd, env=new_env)
4954

5055

51-
@app.command('save-snapshot')
56+
@app.command('save-snapshot', help="Save a snapshot of the current ComfyUI environment")
5257
def save_snapshot():
5358
execute_cm_cli(['save-snapshot'])
5459

comfy_cli/constants.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
from enum import Enum
2+
import os
3+
4+
class OS(Enum):
5+
WINDOWS = 'windows'
6+
MACOS = 'macos'
7+
LINUX = 'linux'
18

29
COMFY_GITHUB_URL = 'https://github.com/comfyanonymous/ComfyUI'
310
COMFY_MANAGER_GITHUB_URL = 'https://github.com/ltdrdata/ComfyUI-Manager'
4-
COMFY_WORKSPACE = '~/comfy'
11+
12+
DEFAULT_COMFY_WORKSPACE = {
13+
OS.WINDOWS: os.path.join(os.path.expanduser('~'), 'Documents', 'ComfyUI'),
14+
OS.MACOS: os.path.join(os.path.expanduser('~'), 'Documents', 'ComfyUI'),
15+
OS.LINUX: os.path.join(os.path.expanduser('~'), 'ComfyUI'),
16+
}
517

618
# TODO: figure out a better way to check if this is a comfy repo
719
COMFY_ORIGIN_URL_CHOICES = [
@@ -15,4 +27,4 @@
1527

1628
# Referencing supported pt extension from ComfyUI
1729
# https://github.com/comfyanonymous/ComfyUI/blob/a88b0ebc2d2f933c94e42aa689c42e836eedaf3c/folder_paths.py#L5
18-
SUPPORTED_PT_EXTENSIONS = set(['.ckpt', '.pt', '.bin', '.pth', '.safetensors'])
30+
SUPPORTED_PT_EXTENSIONS = ('.ckpt', '.pt', '.bin', '.pth', '.safetensors')

comfy_cli/env_checker.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ def check_comfy_server_running():
4848
except requests.exceptions.RequestException:
4949
return False
5050

51+
def check_comfy_repo(path):
52+
try:
53+
repo = git.Repo(path, search_parent_directories=False)
54+
path_is_comfy_repo = any(
55+
remote.url in constants.COMFY_ORIGIN_URL_CHOICES for remote in repo.remotes
56+
)
57+
if path_is_comfy_repo:
58+
return path_is_comfy_repo, repo
59+
else:
60+
return False, None
61+
# Not in a git repo at all
62+
except git.exc.InvalidGitRepositoryError:
63+
return False, None
64+
5165

5266
@singleton
5367
class EnvChecker(object):
@@ -74,6 +88,7 @@ def __init__(self):
7488
self.conda_env = None
7589
self.python_version: None = None
7690
self.currently_in_comfy_repo = False
91+
self.installed_in_default_repo = False
7792
self.comfy_repo = None
7893
self.config = configparser.ConfigParser()
7994
self.check()
@@ -109,24 +124,22 @@ def check(self):
109124
self.virtualenv_path = (
110125
os.environ.get("VIRTUAL_ENV")
111126
if os.environ.get("VIRTUAL_ENV")
112-
else "Not Used"
127+
else None
113128
)
114129
self.conda_env = (
115130
os.environ.get("CONDA_DEFAULT_ENV")
116131
if os.environ.get("CONDA_DEFAULT_ENV")
117-
else "Not Used"
132+
else None
118133
)
119134
self.python_version = sys.version_info
120135

121-
try:
122-
repo = git.Repo(os.getcwd(), search_parent_directories=False)
123-
self.currently_in_comfy_repo = any(
124-
remote.url in constants.COMFY_ORIGIN_URL_CHOICES for remote in repo.remotes
125-
)
126-
if self.currently_in_comfy_repo:
127-
self.comfy_repo = repo
128-
except git.exc.InvalidGitRepositoryError:
136+
is_comfy_repo, repo = check_comfy_repo(os.getcwd())
137+
if is_comfy_repo:
138+
self.currently_in_comfy_repo = True
139+
self.comfy_repo = repo
140+
else:
129141
self.currently_in_comfy_repo = False
142+
self.comfy_repo = None
130143

131144
config_path = self.get_config_path()
132145
if os.path.exists(config_path):
@@ -137,8 +150,8 @@ def print(self):
137150
table = Table(":laptop_computer: Environment", "Value")
138151
table.add_row("Python Version", format_python_version(sys.version_info))
139152
table.add_row("Python Executable", sys.executable)
140-
table.add_row("Virtualenv Path", self.virtualenv_path)
141-
table.add_row("Conda Env", self.conda_env)
153+
table.add_row("Virtualenv Path", self.virtualenv_path if self.virtualenv_path else "Not Used")
154+
table.add_row("Conda Env", self.conda_env if self.conda_env else "Not Used")
142155
if self.config.has_section('DEFAULT') and self.config.has_option('DEFAULT', 'recent_path'):
143156
table.add_row("Recent ComfyUI", self.config['DEFAULT']['recent_path'])
144157
else:

comfy_cli/meta_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
import os
66

7+
from comfy_cli.env_checker import EnvChecker
78
from comfy_cli.utils import singleton
89
from comfy_cli import constants
910

@@ -16,6 +17,7 @@ class MetadataManager:
1617
"""
1718
def __init__(self):
1819
self.metadata_file = None
20+
self.env_checker = EnvChecker()
1921
self.metadata = {}
2022

2123

pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ keywords = ["comfyui", "stable diffusion"]
1414
maintainers = [
1515
{name = "Yoland Yan", email = "yoland@drip.art"},
1616
{name = "James Kwon", email = "hongilkwon316@gmail.com"},
17-
{name = "Robin Huang", email = "robin@drip.art"}
17+
{name = "Robin Huang", email = "robin@drip.art"},
18+
{name = "Dr.Lt.Data", email = "dr.lt.data@gmail.com"}
1819
]
1920

2021
dependencies = [
@@ -33,9 +34,9 @@ classifiers = [
3334
]
3435

3536
[project.scripts]
36-
comfy = "comfy_cli.__main__:app"
37-
comfy-cli = "comfy_cli.__main__:app"
38-
comfycli = "comfy_cli.__main__:app"
37+
comfy = "comfy_cli.__main__:main"
38+
comfy-cli = "comfy_cli.__main__:main"
39+
comfycli = "comfy_cli.__main__:main"
3940

4041
[project.urls]
4142
Repository = "https://github.com/drip-art/comfy-cli.git"

0 commit comments

Comments
 (0)