Skip to content

Commit

Permalink
revert: Remove HTML repr of Items
Browse files Browse the repository at this point in the history
Closes #1161
  • Loading branch information
auguste-probabl committed Jan 20, 2025
1 parent 8ea3238 commit 895b91c
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions skore/src/skore/persistence/item/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
import inspect
from abc import ABC, abstractmethod
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Optional
from uuid import uuid4

from jinja2 import Environment, FileSystemLoader


class ItemTypeError(Exception):
Expand Down Expand Up @@ -89,33 +85,6 @@ def __repr__(self) -> str:
"""Represent the item."""
return f"{self.__class__.__name__}(...)"

def _repr_mimebundle_(self, include=None, exclude=None):
return {"text/html": self._repr_html_()}

def _repr_html_(self):
"""Represent the item in a notebook."""
item_folder = Path(__file__).resolve().parent
templates_env = Environment(loader=FileSystemLoader(item_folder))
template = templates_env.get_template("standalone_widget.html.jinja")

static_files_path = item_folder.parent / "ui" / "static" / "assets"

def read_asset_content(path):
with open(static_files_path / path) as f:
return f.read()

script_content = read_asset_content("index.js")
styles_content = read_asset_content("index.css")

context = {
"id": uuid4().hex,
"item": self.as_serializable_dict(),
"script": script_content,
"styles": styles_content,
}

return template.render(**context)

def as_serializable_dict(self):
"""Convert item to a JSON-serializable dict to used by frontend.
Expand Down

0 comments on commit 895b91c

Please sign in to comment.