Coverage for install/scipp/object_list.py: 0%
16 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3# @file
4# @author Simon Heybrock
5from .visualization import make_html
8def _repr_html_():
9 import inspect
11 # Is there a better way to get the scope? The `7` is hard-coded for the
12 # current IPython stack when calling _repr_html_ so this is bound to break.
13 scope = inspect.stack()[7][0].f_globals
14 from IPython import get_ipython
16 ipython = get_ipython()
17 out = ''
18 for category in ['Variable', 'DataArray', 'Dataset', 'DataGroup']:
19 names = ipython.magic(f"who_ls {category}")
20 out += (
21 f"<details open=\"open\"><summary>{category}s:" f"({len(names)})</summary>"
22 )
23 for name in names:
24 html = make_html(eval(name, scope)) # noqa: S307
25 out += (
26 f"<details style=\"padding-left:2em\"><summary>"
27 f"{name}</summary>{html}</details>"
28 )
29 out += "</details>"
30 from IPython.core.display import HTML, display
32 display(HTML(out))