Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Add new entries under `## [Unreleased]`, in the category they belong to. At rele

## [Unreleased]

### Added

- `fasthep render graph <build dir>` renders `graph/graph.d2` of a compile output directory to
`graph/graph.svg`. The compile step skips this for large graphs (fasthep-render), and its warning
names this command.

### Changed

- Depends on `fasthep-flow`, `fasthep-curator`, `fasthep-render`, and `fasthep-toolbench[display,http]`
Expand Down
26 changes: 26 additions & 0 deletions src/fasthep_cli/commands/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,29 @@ def render_spec_command(
typer.echo("Render complete")
typer.echo(f"Status: {outcome.status.value}")
typer.echo(f"Output: {outcome.output_path}")


@render_app.command("graph")
def render_graph_command(
build_dir: Path = typer.Argument(
...,
exists=True,
file_okay=False,
help="Compile output directory (the --outdir of fasthep compile or run).",
),
) -> None:
"""Render graph/graph.d2 of a compile output directory to graph/graph.svg.

The compile step skips this for large graphs because it can take minutes.
"""
try:
graph_hooks = import_module("fasthep_render.graph.compile_hooks")
except ModuleNotFoundError as exc:
msg = "fasthep-render is required for 'fasthep render graph'"
raise typer.BadParameter(msg) from exc

result = graph_hooks.render_compile_graph(build_dir)
typer.echo(f"Status: {result['status']}")
if result.get("message"):
typer.echo(f"Message: {result['message']}")
typer.echo(f"Output: {result['output']}")
23 changes: 23 additions & 0 deletions tests/test_cli_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

import fasthep_render.api as render_api
import fasthep_render.graph.compile_hooks as graph_hooks
import pytest
import yaml
from fasthep_render.model import RenderStatus
Expand Down Expand Up @@ -190,3 +191,25 @@ def test_render_command_has_no_dispatch_helpers() -> None:
assert not hasattr(render_command_module, "render_resolved")
assert not hasattr(render_command_module, "resolve_runtime_registry")
assert not hasattr(render_command_module, "read_pickle")


def test_render_graph_command_renders_the_compile_graph(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
calls: list[tuple[Path, int | None]] = []

def fake_render_compile_graph(
build_root: Path, *, max_bytes: int | None = None
) -> dict[str, str]:
calls.append((build_root, max_bytes))
return {"status": "rendered", "output": str(build_root / "graph" / "graph.svg")}

monkeypatch.setattr(graph_hooks, "render_compile_graph", fake_render_compile_graph)

result = runner.invoke(app, ["render", "graph", str(tmp_path)])

assert result.exit_code == 0, strip_ansi(result.output)
assert calls == [(tmp_path, None)]
assert "Status: rendered" in result.output
assert str(tmp_path / "graph" / "graph.svg") in result.output
Loading