Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ history.

### Fixed

- The workspace venv that `comfy install` creates (comfy-cli in pipx, uv tool
or a PEP 668 system Python) now upgrades its pip. The bundled pip (22.3.1 on
Python 3.11) could not install torch from the PyTorch index (`No matching
distribution found for flit_core<4,>=3.11`). The upgrade is best effort: if
it fails or times out, the venv is kept and a warning is printed.
- A long partner-node run on a local ComfyUI, signed in with `comfy cloud
login`, no longer stops with "Unauthorized: Please login first" after the
provider task was created, wherever Comfy Cloud issues partner-node tokens
Expand Down
17 changes: 17 additions & 0 deletions comfy_cli/resolve_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,30 @@ def resolve_workspace_python(workspace_path: str | None = None) -> str:
return sys.executable


def _upgrade_pip(python: str) -> bool:
# The pip that venv seeds can be too old for the PyTorch index (flit_core error).
try:
result = subprocess.run(
[python, "-m", "pip", "install", "-q", "-U", "pip"]
+ ["--no-input", "--disable-pip-version-check", "--retries", "1"],
capture_output=True,
timeout=60,
check=False,
)
except subprocess.TimeoutExpired:
return False
return result.returncode == 0


def create_workspace_venv(workspace_path: str) -> str:
venv_dir = os.path.join(workspace_path, ".venv")
rprint(f"Creating workspace virtual environment at [bold]{venv_dir}[/bold]")
subprocess.run([sys.executable, "-m", "venv", venv_dir], check=True)
python = _get_python_binary(venv_dir)
if not os.path.isfile(python):
raise RuntimeError(f"Failed to create venv: {python} not found after creation")
if not _upgrade_pip(python):
rprint("[yellow]Could not upgrade pip in the new venv, continuing with the bundled one.[/yellow]")
return python


Expand Down
21 changes: 21 additions & 0 deletions tests/comfy_cli/test_resolve_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,27 @@ def test_created_venv_has_pip(self, tmp_path):
assert r.returncode == 0
assert "pip" in r.stdout

@pytest.mark.parametrize("failure", ["exit", "timeout"])
def test_failed_pip_upgrade_keeps_venv_and_warns(self, tmp_path, failure):
workspace = tmp_path / "workspace"
workspace.mkdir()
real_run = subprocess.run

def fake_run(cmd, *args, **kwargs):
if cmd[1:4] == ["-m", "pip", "install"]:
if failure == "timeout":
raise subprocess.TimeoutExpired(cmd, kwargs.get("timeout"))
return subprocess.CompletedProcess(cmd, 1, b"", b"ERROR")
return real_run(cmd, *args, **kwargs)

with (
patch("comfy_cli.resolve_python.subprocess.run", side_effect=fake_run),
patch("comfy_cli.resolve_python.rprint") as mock_rprint,
):
result = create_workspace_venv(str(workspace))
assert os.path.isfile(result)
assert any("Could not upgrade pip" in str(c) for c in mock_rprint.call_args_list)

def test_created_venv_is_isolated(self, tmp_path):
workspace = tmp_path / "workspace"
workspace.mkdir()
Expand Down
Loading