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
2 changes: 1 addition & 1 deletion comfy_cli/command/custom_nodes/cm_cli_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from functools import lru_cache

import typer
from rich import print

from comfy_cli.config_manager import ConfigManager
from comfy_cli.output import rprint as print # noqa: A001 - context-aware: stderr in JSON mode
from comfy_cli.resolve_python import resolve_workspace_python
from comfy_cli.uv import DependencyCompiler
from comfy_cli.workspace_manager import WorkspaceManager, check_comfy_repo
Expand Down
8 changes: 8 additions & 0 deletions comfy_cli/command/generate/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@

import httpx
import typer

# NOT migrated to `comfy_cli.output.rprint` on purpose. `generate` carries its own
# `--json` flag (see `_emit_result` / `output.print_json`) and never emits a
# renderer envelope on its submit/sync/resume paths. Routing these calls through
# the shim would send the command's *primary result* (job ids, image URLs) to
# stderr whenever stdout isn't a TTY, leaving stdout empty -- so `comfy generate
# ... > out.txt` would write an empty file. Migrate only once `generate` emits
# envelopes via the renderer.
from rich import print as rprint
from rich.progress import Progress, SpinnerColumn, TextColumn, TimeElapsedColumn

Expand Down
4 changes: 4 additions & 0 deletions comfy_cli/command/generate/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from pathlib import Path

import httpx

# NOT migrated to `comfy_cli.output.rprint` on purpose: `print_urls` / `print_saved`
# are `generate`'s primary result, and `generate` emits no renderer envelope. See
# the note in `comfy_cli/command/generate/app.py`.
from rich import print as rprint

from comfy_cli.command.generate import client
Expand Down
7 changes: 7 additions & 0 deletions comfy_cli/command/pr_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"""

import typer

# NOT migrated to `comfy_cli.output.rprint` on purpose. `pr list` renders its
# result through the module-level `console` below (plain Rich -> stdout) and emits
# no renderer envelope. Routing only these calls through the shim would split one
# command's output across two streams in JSON mode -- table on stdout, "no cached
# PR builds found" / cache settings on stderr. Migrate `console` and these calls
# together, once `pr` emits envelopes via the renderer.
from rich import print as rprint
from rich.console import Console
from rich.table import Table
Expand Down
10 changes: 9 additions & 1 deletion comfy_cli/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
`Renderer.resolve(...)` and stored as a process-wide singleton via `set_renderer`.

Migration policy (Phase 1):
- Every existing ``from rich import print as rprint`` becomes
- A ``from rich import print as rprint`` whose output is a *log or hint* becomes
``from comfy_cli.output import rprint``. The shim suppresses stdout in JSON
mode (redirecting to stderr so logs are still visible) and is byte-identical
to rprint in pretty mode.
- A call site that prints a command's *primary result* must NOT be migrated
until that command emits a ``renderer.emit(...)`` envelope. ``resolve()``
selects JSON mode whenever stdout is not a TTY, so migrating a result path
first would route the result to stderr and leave stdout empty -- e.g.
``comfy generate ... > out.txt`` would write an empty file. The known
un-migrated result paths are ``command/generate/app.py``,
``command/generate/output.py`` and ``command/pr_command.py``; each carries an
in-file comment saying so.
- Commands that produce a structured result emit a final envelope with
``renderer.emit(data)``. This is the *only* thing on stdout in JSON mode.
- Streaming commands emit ``renderer.event(type, **fields)`` events; one
Expand Down
3 changes: 2 additions & 1 deletion comfy_cli/output/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ def _show_video_info(path: Path) -> None:
size_bytes = int(fmt.get("size", 0))
size_mb = size_bytes / 1048576

from rich import print as rprint
from rich.panel import Panel

from comfy_cli.output import rprint

rprint(
Panel(
f"🎬 [bold]{path.name}[/bold]\n {w}×{h} · {fps:.0f}fps · {codec} · {duration:.1f}s · {size_mb:.1f}MB",
Expand Down
3 changes: 1 addition & 2 deletions comfy_cli/pr_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from datetime import datetime, timedelta
from pathlib import Path

from rich import print as rprint

from comfy_cli.config_manager import ConfigManager
from comfy_cli.output import rprint


class PRCache:
Expand Down
2 changes: 1 addition & 1 deletion comfy_cli/resolve_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import sysconfig

from rich import print as rprint
from comfy_cli.output import rprint


def _get_python_binary(env_path: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion comfy_cli/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _check_call(cmd: list[str], cwd: PathLike | None = None):
subprocess.check_call(cmd, cwd=cwd)
except subprocess.CalledProcessError:
if len(cmd) >= 5 and cmd[1:4] == ["-m", "uv", "pip"] and cmd[4] in ("install", "sync"):
from rich import print as rprint
from comfy_cli.output import rprint

rprint(
"\n[bold yellow]Hint:[/bold yellow] If you are on a network filesystem "
Expand Down
Loading