Skip to content

Commit 291b264

Browse files
authored
fix: --fast-deps now respects --skip-torch-or-directml (#382)
1 parent c106693 commit 291b264

5 files changed

Lines changed: 82 additions & 8 deletions

File tree

comfy_cli/command/install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def execute(
287287
gpu=gpu,
288288
cuda_version=cuda_version.value,
289289
rocm_version=rocm_version.value,
290+
skip_torch=skip_torch_or_directml,
290291
)
291292
depComp.compile_deps()
292293
depComp.install_deps()

comfy_cli/uv.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def __init__(
367367
extraSpecs: list[str] | None = None,
368368
cuda_version: str | None = None,
369369
rocm_version: str | None = None,
370+
skip_torch: bool = False,
370371
):
371372
"""Compiler/installer of Python dependencies based on uv
372373
@@ -379,16 +380,21 @@ def __init__(
379380
reqFilesCore (Optional[list[PathLike]]): list of core requirement files (requirements.txt, pyproject.toml, etc) to be included in the compilation. Any requirements determined from these files will override all other requirements
380381
reqFilesExt (Optional[list[PathLike]]): list of requirement files (requirements.txt, pyproject.toml, etc) to be included in the compilation
381382
extraSpecs (Optional[list[str]]): list of extra Python requirement specifiers to be included in the compilation
383+
skip_torch (bool): if True, skip torch/torchvision/torchaudio installation and GPU index URLs
382384
"""
383385
self.cwd = Path(cwd).expanduser().resolve()
384386
self.outDir: Path = Path(outDir).expanduser().resolve()
385387
# use .absolute since .resolve breaks the softlink-is-interpreter assumption of venvs
386388
self.executable = Path(executable).expanduser().absolute()
387389
self.gpu = DependencyCompiler.Resolve_Gpu(gpu)
390+
self.skip_torch = skip_torch
388391
self.reqFiles = [Path(reqFile) for reqFile in reqFilesExt] if reqFilesExt is not None else None
389392
self.extraSpecs = [] if extraSpecs is None else extraSpecs
390393

391-
if self.gpu == GPU_OPTION.NVIDIA:
394+
if self.skip_torch:
395+
self.gpuUrl = None
396+
self.torchBackend = None
397+
elif self.gpu == GPU_OPTION.NVIDIA:
392398
tag = f"cu{cuda_version.replace('.', '')}" if cuda_version else DependencyCompiler.nvidiaTorchBackend
393399
self.gpuUrl = f"https://download.pytorch.org/whl/{tag}"
394400
self.torchBackend = tag

tests/comfy_cli/test_install_python_resolution.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ def test_fast_deps_passes_python_to_dependency_compiler(self, tmp_path):
9898
MockCompiler.Install_Build_Deps.assert_called_once_with(executable="/resolved/python")
9999
MockCompiler.assert_called_once()
100100
assert MockCompiler.call_args[1]["executable"] == "/resolved/python"
101+
assert MockCompiler.call_args[1].get("skip_torch") in (None, False)
102+
103+
def test_fast_deps_forwards_skip_torch(self, tmp_path):
104+
repo_dir = str(tmp_path)
105+
106+
with (
107+
patch("comfy_cli.command.install.ensure_workspace_python", return_value="/resolved/python"),
108+
patch("comfy_cli.command.install.clone_comfyui"),
109+
patch("comfy_cli.command.install.check_comfy_repo", return_value=(True, None)),
110+
patch("comfy_cli.command.install.DependencyCompiler") as MockCompiler,
111+
patch("comfy_cli.command.install.WorkspaceManager"),
112+
patch.object(install.workspace_manager, "skip_prompting", True),
113+
patch.object(install.workspace_manager, "setup_workspace_manager"),
114+
):
115+
MockCompiler.Install_Build_Deps = MagicMock()
116+
mock_instance = MagicMock()
117+
MockCompiler.return_value = mock_instance
118+
119+
install.execute(
120+
url="https://github.com/test/test.git",
121+
manager_url="https://github.com/test/manager.git",
122+
comfy_path=repo_dir,
123+
restore=False,
124+
skip_manager=True,
125+
version="nightly",
126+
fast_deps=True,
127+
skip_torch_or_directml=True,
128+
)
129+
130+
assert MockCompiler.call_args[1]["skip_torch"] is True
101131

102132

103133
def _get_torch_install_cmd(calls):

tests/e2e/test_e2e.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,25 @@ def test_node(comfy_cli, workspace):
109109
break
110110
assert proc.returncode == 0, f"node install failed after 3 attempts:\n{proc.stderr}"
111111

112-
proc = exec(
113-
f"""
114-
{comfy_cli} node reinstall {node}
115-
"""
116-
)
117-
assert proc.returncode == 0
112+
for attempt in range(3):
113+
proc = exec(
114+
f"""
115+
{comfy_cli} node reinstall {node}
116+
"""
117+
)
118+
if proc.returncode == 0:
119+
break
120+
assert proc.returncode == 0, f"node reinstall failed after 3 attempts:\n{proc.stderr}"
118121

119122
proc = exec(
120123
f"""
121124
{comfy_cli} node show all
122125
"""
123126
)
124127
assert proc.returncode == 0
125-
assert node in proc.stdout
128+
# cm-cli may display the repo name (ComfyUI-AnimateDiff-Evolved) rather
129+
# than the registry id (comfyui-animatediff-evolved), so compare lowercase.
130+
assert node.lower() in proc.stdout.lower()
126131

127132
proc = exec(
128133
f"""

tests/uv/test_uv.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,35 @@ def test_amd_custom_rocm_version():
177177
)
178178
assert depComp.torchBackend == "rocm7.1"
179179
assert depComp.gpuUrl == "https://download.pytorch.org/whl/rocm7.1"
180+
181+
182+
@pytest.mark.parametrize("gpu", [GPU_OPTION.NVIDIA, GPU_OPTION.AMD, GPU_OPTION.CPU])
183+
def test_skip_torch_disables_gpu_url_and_backend(gpu):
184+
depComp = DependencyCompiler(cwd=temp, gpu=gpu, outDir=temp, reqFilesCore=[], reqFilesExt=[], skip_torch=True)
185+
assert depComp.torchBackend is None
186+
assert depComp.gpuUrl is None
187+
188+
189+
def test_skip_torch_override_has_no_torch():
190+
depComp = DependencyCompiler(
191+
cwd=temp,
192+
gpu=GPU_OPTION.NVIDIA,
193+
outDir=temp,
194+
reqFilesCore=[mockReqsDir / "core_reqs.txt"],
195+
reqFilesExt=[],
196+
skip_torch=True,
197+
)
198+
depComp.make_override()
199+
content = depComp.override.read_text()
200+
assert "torch" not in content
201+
202+
203+
def test_skip_torch_install_deps_no_extra_index_url():
204+
depComp = DependencyCompiler(
205+
cwd=temp, gpu=GPU_OPTION.NVIDIA, outDir=temp, reqFilesCore=[], reqFilesExt=[], skip_torch=True
206+
)
207+
depComp.out.write_text("requests==2.31.0\n")
208+
with patch("comfy_cli.uv._check_call") as mock_check_call:
209+
depComp.install_deps()
210+
cmd = mock_check_call.call_args[0][0]
211+
assert "--extra-index-url" not in cmd

0 commit comments

Comments
 (0)