Skip to content

Commit 78b63fe

Browse files
authored
fix: invalid logics when execute command based on not installed workspace (#82)
* fix: invalid logics when execute command based on not installed workspace #81 * remove useless startup scan code
1 parent a271264 commit 78b63fe

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

comfy_cli/cmdline.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ def entry(
122122
)
123123
print(ctx.get_help())
124124
ctx.exit()
125-
start_time = time.time()
126-
workspace_manager.scan_dir()
127-
end_time = time.time()
128125

129-
logging.info(f"scan_dir took {end_time - start_time:.2f} seconds to run")
126+
# TODO: Move this to proper place
127+
# start_time = time.time()
128+
# workspace_manager.scan_dir()
129+
# end_time = time.time()
130+
#
131+
# logging.info(f"scan_dir took {end_time - start_time:.2f} seconds to run")
130132

131133

132134
gpu_exclusivity_callback = mutually_exclusive_group_options()
@@ -602,6 +604,7 @@ def launch(
602604
):
603605
check_for_updates()
604606
resolved_workspace = workspace_manager.workspace_path
607+
605608
if not resolved_workspace:
606609
print(
607610
"\nComfyUI is not available.\nTo install ComfyUI, you can run:\n\n\tcomfy install\n\n",
@@ -642,12 +645,18 @@ def set_default(
642645
comfy_path = os.path.abspath(os.path.expanduser(workspace_path))
643646

644647
if not os.path.exists(comfy_path):
645-
print(f"Path not found: {comfy_path}.")
648+
print(
649+
f"\nPath not found: {comfy_path}.\n",
650+
file=sys.stderr,
651+
)
646652
raise typer.Exit(code=1)
647653

648654
is_comfy_repo, comfy_repo = check_comfy_repo(comfy_path)
649655
if not is_comfy_repo:
650-
print(f"Specified path is not a ComfyUI path: {comfy_path}.")
656+
print(
657+
f"\nSpecified path is not a ComfyUI path: {comfy_path}.\n",
658+
file=sys.stderr,
659+
)
651660
raise typer.Exit(code=1)
652661

653662
comfy_path = comfy_repo.working_dir

comfy_cli/command/custom_nodes/command.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ def execute_cm_cli(args, channel=None, mode=None):
3535

3636
workspace_path = workspace_manager.workspace_path
3737

38-
if not os.path.exists(workspace_path):
39-
print(f"\nComfyUI not found: {workspace_path}\n", file=sys.stderr)
38+
if not workspace_path:
39+
print(
40+
f"\n[bold red]ComfyUI path is not resolved.[/bold red]\n", file=sys.stderr
41+
)
4042
raise typer.Exit(code=1)
4143

4244
cm_cli_path = os.path.join(
4345
workspace_path, "custom_nodes", "ComfyUI-Manager", "cm-cli.py"
4446
)
4547
if not os.path.exists(cm_cli_path):
46-
print(f"\nComfyUI-Manager not found: {cm_cli_path}\n", file=sys.stderr)
48+
print(
49+
f"\n[bold red]ComfyUI-Manager not found: {cm_cli_path}[/bold red]\n",
50+
file=sys.stderr,
51+
)
4752
raise typer.Exit(code=1)
4853

4954
cmd = [sys.executable, cm_cli_path] + args
@@ -66,7 +71,7 @@ def execute_cm_cli(args, channel=None, mode=None):
6671
subprocess.run(cmd, env=new_env, check=True)
6772
except subprocess.CalledProcessError as e:
6873
if e.returncode == 1:
69-
print(f"Execution error: {cmd}", file=sys.stderr)
74+
print(f"\n[bold red]Execution error: {cmd}[/bold red]\n", file=sys.stderr)
7075
elif e.returncode == 2:
7176
pass
7277
else:

comfy_cli/command/install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def execute(
189189
)
190190

191191
WorkspaceManager().set_recent_workspace(repo_dir)
192+
workspace_manager.setup_workspace_manager(specified_workspace=repo_dir)
192193

193194
print("")
194195

comfy_cli/workspace_manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,20 @@ def get_workspace_path(self) -> Tuple[str, WorkspaceType]:
275275
constants.CONFIG_KEY_DEFAULT_WORKSPACE
276276
)
277277

278-
if default_workspace and check_comfy_repo(default_workspace):
278+
if default_workspace and check_comfy_repo(default_workspace)[0]:
279279
return default_workspace, WorkspaceType.DEFAULT
280280

281281
# Fallback to the most recent workspace if it exists
282282
if self.use_recent is None:
283283
recent_workspace = self.config_manager.get(
284284
constants.CONFIG_KEY_RECENT_WORKSPACE
285285
)
286-
if recent_workspace and check_comfy_repo(recent_workspace):
286+
if recent_workspace and check_comfy_repo(recent_workspace)[0]:
287287
return recent_workspace, WorkspaceType.RECENT
288288

289289
# Check for comfy-cli default workspace
290290
default_workspace = utils.get_not_user_set_default_workspace()
291-
if check_comfy_repo(default_workspace):
291+
if check_comfy_repo(default_workspace)[0]:
292292
return default_workspace, WorkspaceType.DEFAULT
293293

294294
return None, WorkspaceType.NOT_FOUND
@@ -314,6 +314,9 @@ def is_comfyui_manager_installed(self):
314314
return os.path.exists(manager_git_path)
315315

316316
def scan_dir(self):
317+
if not self.workspace_path:
318+
return []
319+
317320
logging.info(f"Scanning directory: {self.workspace_path}")
318321
model_files = []
319322
for root, _dirs, files in os.walk(self.workspace_path):

0 commit comments

Comments
 (0)