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
3 changes: 2 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ jobs:
prefix = "rtichoke/_vendor/rtichoke_viz/"
required = {
f"{prefix}VENDORED_FROM",
f"{prefix}rtichoke-viz-0.20.1.tar.gz",
f"{prefix}rtichoke-viz-0.20.2.tar.gz",
f"{prefix}rtichoke-viz.js",
f"{prefix}rtichoke-viz.css",
f"{prefix}rtichoke-viz.schema.json",
f"{prefix}rtichoke-viz-v2.schema.json",
f"{prefix}rtichoke-viz-report.schema.json",
}
assert required <= names
assert f"{prefix}rtichoke-viz-0.20.1.tar.gz" not in names
assert f"{prefix}rtichoke-viz-0.20.0.tar.gz" not in names
assert f"{prefix}rtichoke-viz-0.19.0.tar.gz" not in names
assert f"{prefix}rtichoke-viz-0.14.0.tar.gz" not in names
Expand Down
31 changes: 29 additions & 2 deletions src/rtichoke/_report_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,37 @@
from __future__ import annotations

import json
import re
from importlib.resources import files
from pathlib import Path
from typing import Any


def _resolve_render_report_symbol(viz_js: str) -> str:
"""Resolve the local callable identifier exported as 'renderReport' from an ESM bundle."""
export_pattern = re.compile(r"export\s*\{([^}]+)\}", re.DOTALL)
for match in export_pattern.finditer(viz_js):
clause = match.group(1)
for item in clause.split(","):
parts = item.strip().split()
if not parts:
continue
if len(parts) == 3 and parts[1] == "as" and parts[2] == "renderReport":
return parts[0]
if len(parts) == 1 and parts[0] == "renderReport":
return "renderReport"

if re.search(
r"export\s+(?:async\s+)?function\s+renderReport\b|export\s+(?:const|let|var)\s+renderReport\b",
viz_js,
):
return "renderReport"

raise ValueError(
"Could not resolve 'renderReport' export in provided JavaScript bundle."
)


def _sanitize_nan_values(obj: Any) -> Any:
"""Recursively replace NaN and Inf float values with None for valid JSON serialization."""
if isinstance(obj, dict):
Expand Down Expand Up @@ -40,6 +66,7 @@ def write_html(self, path: str | Path) -> Path:
)
viz_js = vendor.joinpath("rtichoke-viz.js").read_text(encoding="utf-8")
viz_css = vendor.joinpath("rtichoke-viz.css").read_text(encoding="utf-8")
render_fn = _resolve_render_report_symbol(viz_js)
html = f"""<!doctype html>
<html lang="en">
<head>
Expand All @@ -58,10 +85,10 @@ def write_html(self, path: str | Path) -> Path:
const spec = JSON.parse(
document.querySelector("#rtichoke-report-spec").textContent
);
document.querySelector("#rtichoke-report").append(renderReport(spec, {{
document.querySelector("#rtichoke-report").append({render_fn}(spec, {{
sectionGroupPresentation: "tabs",
groupPresentation: "stacked"
}}));
}}));
</script>
</body>
</html>
Expand Down
8 changes: 4 additions & 4 deletions src/rtichoke/_vendor/rtichoke_viz/VENDORED_FROM
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repository=https://github.com/uriahf/rtichoke_viz
release=v0.20.1
source_commit=56e097ab394f3499ef5cfe791e686248df8b39f2
archive=rtichoke-viz-0.20.1.tar.gz
sha256=17aebfb05a479c3ea28855f6ca3f43cadde7b8b134a2080e309c630c63617629
release=v0.20.2
source_commit=40748bdeff7d535f516744886b64056f3aaa518d
archive=rtichoke-viz-0.20.2.tar.gz
sha256=2e4851159ceea0e3b2420c7e0aa22a566b94ec7057c27b13b7db7da88de34d11
Binary file not shown.
Binary file not shown.
Loading
Loading