From 2db21d22a4af1600aa003036c14edfc460111cdd Mon Sep 17 00:00:00 2001 From: Edan Bainglass Date: Thu, 11 Jul 2024 05:23:19 +0000 Subject: [PATCH] Load CSS stylesheets on `from aiidalab_widgets_base...` import --- aiidalab_widgets_base/__init__.py | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/aiidalab_widgets_base/__init__.py b/aiidalab_widgets_base/__init__.py index 63b2bf7c2..16ad05f38 100644 --- a/aiidalab_widgets_base/__init__.py +++ b/aiidalab_widgets_base/__init__.py @@ -1,7 +1,5 @@ """Reusable widgets for AiiDAlab applications.""" -from aiida.manage import get_profile - _WARNING_TEMPLATE = """

Warning:

@@ -27,22 +25,31 @@ def is_running_in_jupyter(): return False -# load the default profile if no profile is loaded, and raise a deprecation warning -# this is a temporary solution to avoid breaking existing notebooks -# this will be removed in the next major release -if is_running_in_jupyter() and get_profile() is None: - # if no profile is loaded, load the default profile and raise a deprecation warning - from aiida import load_profile +if is_running_in_jupyter(): + from aiida.manage import get_profile from IPython.display import HTML, display - load_profile() + # load the default profile if no profile is loaded, and raise a deprecation warning + # this is a temporary solution to avoid breaking existing notebooks + # this will be removed in the next major release + if get_profile() is None: + # if no profile is loaded, load the default profile and raise a deprecation warning + from aiida import load_profile + + load_profile() + + profile = get_profile() + assert profile is not None, "Failed to load the default profile" + + # raise a deprecation warning + warning = HTML(_WARNING_TEMPLATE.format(profile=profile.name, version="v3.0.0")) + display(warning) + + from .static import styles + from .utils.loaders import load_css_stylesheet - profile = get_profile() - assert profile is not None, "Failed to load the default profile" + load_css_stylesheet(package=styles) - # raise a deprecation warning - warning = HTML(_WARNING_TEMPLATE.format(profile=profile.name, version="v3.0.0")) - display(warning) from .computational_resources import ( ComputationalResourcesWidget,