bencher.utils_rrd ================= .. py:module:: bencher.utils_rrd .. autoapi-nested-parse:: Utilities for serving and viewing .rrd files without the rerun Python SDK. This module provides functions for displaying pre-recorded .rrd files (e.g. those produced by the C++ rerun library) in Panel reports. It does NOT depend on the ``rerun-sdk`` package, so downstream projects that cannot install it (e.g. because of a NumPy 2 requirement) can still use these utilities. See ``utils_rerun.py`` for functions that require the rerun Python SDK (live capture, recording management, etc.). Attributes ---------- .. autoapisummary:: bencher.utils_rrd._RRD_CACHE_DIR bencher.utils_rrd._VERSION_RE bencher.utils_rrd._CDN_VIEWER_TEMPLATE bencher.utils_rrd._CDN_VIEWER_INLINE_TEMPLATE bencher.utils_rrd._cdn_viewer_files bencher.utils_rrd._cdn_viewer_html bencher.utils_rrd._RRD_URL_RE Functions --------- .. autoapisummary:: bencher.utils_rrd._get_rerun_version bencher.utils_rrd.rrd_to_pane bencher.utils_rrd.publish_and_view_rrd bencher.utils_rrd.rrd_file_to_pane bencher.utils_rrd._wrap_viewer_controls bencher.utils_rrd._cdn_viewer_url bencher.utils_rrd._get_cdn_viewer_html bencher.utils_rrd._write_rrd_sidecar bencher.utils_rrd._portable_rrd_pane bencher.utils_rrd._write_inline_viewer bencher.utils_rrd.inline_rrd_iframes Module Contents --------------- .. py:data:: _RRD_CACHE_DIR .. py:data:: _VERSION_RE .. py:function:: _get_rerun_version() -> str Get the installed rerun package version, or a sensible default. .. py:function:: rrd_to_pane(url: str, width: int = 500, height: int = 600, version: str | None = None) Display an .rrd file from a URL using the hosted rerun web viewer. .. py:function:: publish_and_view_rrd(file_path: str, remote: str, branch_name: str, content_callback: callable, version: str | None = None) .. py:function:: rrd_file_to_pane(file_path, width: int = 300, height: int = 300, viewer_version: str | None = None, report_dir: str | pathlib.Path | None = None) Create a rerun viewer pane from an .rrd file path. Uses an HTML iframe to display the .rrd file. By default the viewer is loaded from the ``@rerun-io/web-viewer`` CDN at the installed ``rerun-sdk`` version. The viewer page and the ``.rrd`` data are both served from the Panel server's ``/rrd_static/`` route, keeping everything on a single origin (no CORS, no extra ports). The file must be located under ``cachedir/rrd/``. :param file_path: Path to the .rrd file (must be under ``cachedir/rrd/``). :param width: Width of the viewer iframe in pixels. :param height: Height of the viewer iframe in pixels. :param viewer_version: Rerun web-viewer version to load from CDN. Defaults to the installed ``rerun-sdk`` version. Set explicitly when the .rrd was recorded with a different SDK version. :param report_dir: When set, copies the .rrd and viewer HTML into this directory and uses relative URLs in the iframe. This makes the report portable — it works when served from any HTTP origin without a live Panel server. .. py:data:: _CDN_VIEWER_TEMPLATE :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """
""" .. raw:: html
.. py:data:: _CDN_VIEWER_INLINE_TEMPLATE :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """
""" .. raw:: html
.. py:function:: _wrap_viewer_controls(iframe_html: str, viewer_url: str, width: int, height: int) -> str Wrap a rerun-viewer iframe with fullscreen and open-in-new-tab controls. Controls float at the top-center (away from the viewer's own corner UI). The anchor's ``href`` is set to *viewer_url* directly so middle-click, Cmd/Ctrl-click, and the context-menu "Open in new tab" all see the right target — not just plain left-click. ``inline_rrd_iframes()`` rewrites both the iframe ``src`` and the anchor ``href`` when a report is saved. A real anchor (rather than ``window.open()``) avoids popup-blocker false positives that silently swallow the click in some browsers. .. py:data:: _cdn_viewer_files :type: dict[str, str] .. py:data:: _cdn_viewer_html :type: dict[str, str] .. py:function:: _cdn_viewer_url(rrd_relative: pathlib.Path, version: str) -> str Return the iframe URL for a CDN-based viewer at the given version. Writes a ``viewer_.html`` page into ``cachedir/rrd/`` (served by the Panel server at ``/rrd_static/``) that loads the rerun web viewer from the jsDelivr CDN. Both the viewer page and the .rrd are on the same HTTP origin, avoiding mixed-content blocks. .. py:function:: _get_cdn_viewer_html(version: str) -> str Return the viewer HTML string for a given rerun version (cached). .. py:function:: _write_rrd_sidecar(rrd_path: pathlib.Path, version: str, dest_dir: pathlib.Path) -> tuple[str, str] Copy an .rrd file and its CDN viewer page into *dest_dir*. Returns ``(viewer_filename, rrd_filename)`` — both relative to *dest_dir*. The viewer page is written idempotently (skipped if already up-to-date). .. py:function:: _portable_rrd_pane(rrd_path: pathlib.Path, version: str, report_dir: pathlib.Path, width: int, height: int) -> panel.pane.HTML Create a self-contained pane with files copied into the report directory. Copies the .rrd and a CDN viewer HTML page into ``report_dir/_rrd/`` and returns an iframe with a relative URL. The resulting report can be served from any HTTP origin without a live Panel server. .. py:data:: _RRD_URL_RE .. py:function:: _write_inline_viewer(rrd_path: pathlib.Path, version: str, dest_dir: pathlib.Path) -> str Create a self-contained viewer HTML with the .rrd data inlined as base64. Returns the filename (relative to *dest_dir*) of the written viewer page. .. py:function:: inline_rrd_iframes(html_path: pathlib.Path, rrd_base: pathlib.Path | None = None, portable: bool = False) -> None Post-process a saved HTML report for static hosting. Scans the HTML file for rerun viewer iframes (those pointing at ``/rrd_static/``), copies the ``.rrd`` files next to the report, and rewrites the iframe ``src`` to relative URLs. :param html_path: Path to the saved HTML file to post-process. :param rrd_base: Directory where ``_rrd/`` should be created. When ``None`` (default), uses ``html_path.parent``. Pass the top-level report directory for multi-tab saves so all tabs share one ``_rrd/``. :param portable: When ``True``, base64-encode the ``.rrd`` data directly into the viewer HTML so the report works from ``file://`` without any server. This can be very slow for large recordings (hundreds of MB or more). When ``False`` (default), the ``.rrd`` is copied as a sidecar file and loaded via a relative URL — the report must be served over HTTP (any static server works). :param Called automatically by ``BenchReport.save()``.: