Skip to content

Commit 828c1f8

Browse files
authored
Add --no-deps to comfy node install. (#315)
1 parent 2244b89 commit 828c1f8

File tree

3 files changed

+114
-4
lines changed

3 files changed

+114
-4
lines changed

comfy_cli/command/custom_nodes/cm_cli_util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222

2323

24-
def execute_cm_cli(args, channel=None, fast_deps=False, mode=None) -> str | None:
24+
def execute_cm_cli(args, channel=None, fast_deps=False, no_deps=False, mode=None) -> str | None:
2525
_config_manager = ConfigManager()
2626

2727
workspace_path = workspace_manager.workspace_path
@@ -43,7 +43,7 @@ def execute_cm_cli(args, channel=None, fast_deps=False, mode=None) -> str | None
4343
if channel is not None:
4444
cmd += ["--channel", channel]
4545

46-
if fast_deps:
46+
if fast_deps or no_deps:
4747
cmd += ["--no-deps"]
4848

4949
if mode is not None:
@@ -55,7 +55,7 @@ def execute_cm_cli(args, channel=None, fast_deps=False, mode=None) -> str | None
5555
new_env["COMFYUI_PATH"] = workspace_path
5656

5757
print(f"Execute from: {workspace_path}")
58-
58+
print(f"Command: {cmd}")
5959
try:
6060
result = subprocess.run(
6161
cmd, env=new_env, check=True, capture_output=True, text=True, encoding="utf-8", errors="replace"

comfy_cli/command/custom_nodes/command.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ def install(
400400
help="Use new fast dependency installer",
401401
),
402402
] = False,
403+
no_deps: Annotated[
404+
bool,
405+
typer.Option(
406+
"--no-deps",
407+
show_default=False,
408+
help="Skip dependency installation",
409+
),
410+
] = False,
403411
exit_on_fail: Annotated[
404412
bool,
405413
typer.Option(
@@ -417,14 +425,18 @@ def install(
417425
typer.echo(f"Invalid command: {mode}. `install all` is not allowed", err=True)
418426
raise typer.Exit(code=1)
419427

428+
if fast_deps and no_deps:
429+
typer.echo("Cannot use --fast-deps and --no-deps together", err=True)
430+
raise typer.Exit(code=1)
431+
420432
validate_mode(mode)
421433

422434
if exit_on_fail:
423435
cmd = ["install", "--exit-on-fail"] + nodes
424436
else:
425437
cmd = ["install"] + nodes
426438

427-
execute_cm_cli(cmd, channel=channel, fast_deps=fast_deps, mode=mode)
439+
execute_cm_cli(cmd, channel=channel, fast_deps=fast_deps, no_deps=no_deps, mode=mode)
428440

429441

430442
@app.command(help="Reinstall custom nodes")
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import re
2+
from unittest.mock import patch
3+
4+
from typer.testing import CliRunner
5+
6+
from comfy_cli.command.custom_nodes.command import app
7+
8+
runner = CliRunner(mix_stderr=False)
9+
10+
11+
def strip_ansi(text):
12+
"""Remove ANSI escape sequences from text."""
13+
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
14+
return ansi_escape.sub("", text)
15+
16+
17+
def test_install_no_deps_option_exists():
18+
"""Test that the --no-deps option appears in the help."""
19+
result = runner.invoke(app, ["install", "--help"])
20+
assert result.exit_code == 0
21+
clean_output = strip_ansi(result.stdout)
22+
assert "--no-deps" in clean_output
23+
assert "Skip dependency installation" in clean_output
24+
25+
26+
def test_install_fast_deps_and_no_deps_mutually_exclusive():
27+
"""Test that --fast-deps and --no-deps cannot be used together."""
28+
result = runner.invoke(app, ["install", "test-node", "--fast-deps", "--no-deps"])
29+
assert result.exit_code != 0
30+
# Check both stdout and stderr for the error message
31+
output = result.stdout + result.stderr
32+
assert "Cannot use --fast-deps and --no-deps together" in output
33+
34+
35+
def test_install_no_deps_alone_works():
36+
"""Test that --no-deps can be used by itself."""
37+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute:
38+
result = runner.invoke(app, ["install", "test-node", "--no-deps"])
39+
40+
# Should not exit with error due to mutual exclusivity
41+
if result.exit_code != 0:
42+
# Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity
43+
assert "Cannot use --fast-deps and --no-deps together" not in result.stdout
44+
45+
# Verify execute_cm_cli was called with no_deps=True
46+
if mock_execute.called:
47+
_, kwargs = mock_execute.call_args
48+
assert kwargs.get("no_deps") is True
49+
assert kwargs.get("fast_deps") is False
50+
51+
52+
def test_install_fast_deps_alone_works():
53+
"""Test that --fast-deps can be used by itself."""
54+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute:
55+
result = runner.invoke(app, ["install", "test-node", "--fast-deps"])
56+
57+
# Should not exit with error due to mutual exclusivity
58+
if result.exit_code != 0:
59+
# Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity
60+
assert "Cannot use --fast-deps and --no-deps together" not in result.stdout
61+
62+
# Verify execute_cm_cli was called with fast_deps=True
63+
if mock_execute.called:
64+
_, kwargs = mock_execute.call_args
65+
assert kwargs.get("fast_deps") is True
66+
assert kwargs.get("no_deps") is False
67+
68+
69+
def test_install_neither_deps_option():
70+
"""Test that install works without any deps options."""
71+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute:
72+
result = runner.invoke(app, ["install", "test-node"])
73+
74+
# Should not exit with error due to mutual exclusivity
75+
if result.exit_code != 0:
76+
# Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity
77+
assert "Cannot use --fast-deps and --no-deps together" not in result.stdout
78+
79+
# Verify execute_cm_cli was called with both flags False
80+
if mock_execute.called:
81+
_, kwargs = mock_execute.call_args
82+
assert kwargs.get("fast_deps") is False
83+
assert kwargs.get("no_deps") is False
84+
85+
86+
def test_multiple_commands_work_independently():
87+
"""Test that multiple commands work independently without state interference."""
88+
# First command with --no-deps should work
89+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli"):
90+
result1 = runner.invoke(app, ["install", "test-node", "--no-deps"])
91+
if result1.exit_code != 0:
92+
assert "Cannot use --fast-deps and --no-deps together" not in result1.stdout
93+
94+
# Second command with --fast-deps should also work
95+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli"):
96+
result2 = runner.invoke(app, ["install", "test-node2", "--fast-deps"])
97+
if result2.exit_code != 0:
98+
assert "Cannot use --fast-deps and --no-deps together" not in result2.stdout

0 commit comments

Comments
 (0)