A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: catch errors when applying themes (#2205)
Myles Scolnick06eda80a6163
diff --git a/marimo/_output/formatters/formatter_factory.py b/marimo/_output/formatters/formatter_factory.pyindex c8933e5c2e..a347117b0b 100644--- a/marimo/_output/formatters/formatter_factory.py+++ b/marimo/_output/formatters/formatter_factory.py@@ -4,8 +4,11 @@ from __future__ import annotationsimport abcfrom typing import Callable, Optional+from marimo import _loggersfrom marimo._config.config import Theme+LOGGER = _loggers.marimo_logger()+# Abstract base class for formatters that are installed at runtime.class FormatterFactory(abc.ABC):@@ -42,3 +45,18 @@ class FormatterFactory(abc.ABC):"""del themereturn++ def apply_theme_safe(self, theme: Theme) -> None:+ """+ Apply the theme (light/dark) to third party libraries.+ If the theme is set to "system", then we fallback to "light".++ Args:+ theme: The theme to apply.+ """+ try:+ self.apply_theme(theme)+ except Exception as e:+ LOGGER.error(+ f"Error applying theme {theme} fro {self.package_name()}: {e}"+ )diff --git a/marimo/_output/formatters/formatters.py b/marimo/_output/formatters/formatters.pyindex db0a638a74..d946e9927c 100644--- a/marimo/_output/formatters/formatters.py+++ b/marimo/_output/formatters/formatters.py@@ -82,7 +82,7 @@ def register_formatters(theme: Theme = "light") -> None:for package, factory in THIRD_PARTY_FACTORIES.items():if package in sys.modules:factory.register()- factory.apply_theme(theme)+ factory.apply_theme_safe(theme)pre_registered.add(package)third_party_factories = {@@ -149,7 +149,7 @@ def register_formatters(theme: Theme = "light") -> None:) -> Any:loader_return_value = original_exec_module(module)factory.register()- factory.apply_theme(theme)+ factory.apply_theme_safe(theme)return loader_return_valuespec.loader.exec_module = exec_module@@ -164,4 +164,4 @@ def register_formatters(theme: Theme = "light") -> None:# package import. So we can register them at program start-up.for factory in NATIVE_FACTORIES:factory.register()- factory.apply_theme(theme)+ factory.apply_theme_safe(theme)