Skip to content

Commit 5cc0d14

Browse files
committed
fix: use absolute path for pip install -r target
try_install_script runs pip with cwd=repo_path, so if requirements_path were relative it would get re-resolved against that cwd, producing a doubled path like <rel>/<rel>/requirements.txt. Wrap the requirements_path with os.path.abspath before handing it to pip to make the -r target unambiguous regardless of whether the caller passes an absolute or relative repo_path. Add a regression test that invokes execute_install_script with a relative repo_path. Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent a399d41 commit 5cc0d14

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

comfy_cli/command/custom_nodes/command.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ def execute_install_script(repo_path):
171171
if os.path.exists(requirements_path):
172172
print("Install: pip packages")
173173
python = resolve_workspace_python(workspace_manager.workspace_path)
174-
install_cmd = [python, "-m", "pip", "install", "-r", requirements_path]
174+
# Absolute path so pip doesn't re-resolve it against cwd=repo_path
175+
# in try_install_script, which would double the path if repo_path
176+
# is relative.
177+
install_cmd = [python, "-m", "pip", "install", "-r", os.path.abspath(requirements_path)]
175178
try_install_script(repo_path, install_cmd)
176179

177180
if os.path.exists(install_script_path):

tests/comfy_cli/test_custom_nodes_python_resolution.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from unittest.mock import patch
23

34
from comfy_cli.command.custom_nodes import command
@@ -104,6 +105,30 @@ def test_uses_pip_install_r(self, tmp_path):
104105
argv = mock_check_call.call_args[0][0]
105106
assert argv == ["/resolved/python", "-m", "pip", "install", "-r", str(requirements_path)]
106107

108+
def test_requirements_path_is_absolute_when_repo_path_is_relative(self, tmp_path, monkeypatch):
109+
# try_install_script runs pip with cwd=repo_path. If requirements_path
110+
# were relative, pip would resolve `-r <rel>/requirements.txt` against
111+
# that cwd, producing a doubled path like <rel>/<rel>/requirements.txt.
112+
# Guard: the `-r` target must be absolute regardless of the input.
113+
(tmp_path / "requirements.txt").write_text("numpy>=1.0\n")
114+
monkeypatch.chdir(tmp_path.parent)
115+
relative_repo = tmp_path.name # e.g. "test_requirements_path..." relative to cwd
116+
117+
with (
118+
patch(
119+
"comfy_cli.command.custom_nodes.command.resolve_workspace_python",
120+
return_value="/resolved/python",
121+
),
122+
patch.object(command.workspace_manager, "workspace_path", str(tmp_path)),
123+
patch("comfy_cli.command.custom_nodes.command.subprocess.check_call") as mock_check_call,
124+
):
125+
command.execute_install_script(relative_repo)
126+
127+
argv = mock_check_call.call_args[0][0]
128+
target = argv[-1]
129+
assert os.path.isabs(target), f"-r target is not absolute: {target!r}"
130+
assert target == str(tmp_path / "requirements.txt")
131+
107132

108133
class TestUpdateNodeIdCache:
109134
def test_uses_resolved_python(self, tmp_path):

0 commit comments

Comments
 (0)