Skip to content
Open
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
23 changes: 20 additions & 3 deletions src/bokeh/embed/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
from __future__ import annotations

import logging # isort:skip
from bokeh.core.has_props import HasProps
from bokeh.core.templates import CSS_RESOURCES, JS_RESOURCES
from bokeh.document.document import Document
from bokeh.embed.util import contains_tex_string
from bokeh.resources import Hashes, Resources
from bokeh.settings import settings
from bokeh.util.compiler import bundle_models

log = logging.getLogger(__name__)

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -382,17 +390,25 @@ def _use_tables(all_objs: set[HasProps]) -> bool:
return _any(all_objs, lambda obj: isinstance(obj, TableWidget)) or _ext_use_tables(all_objs)

def _use_widgets(all_objs: set[HasProps]) -> bool:
''' Whether a collection of Bokeh objects contains a any Widget
""" Whether a collection of Bokeh objects contains a any Widget

Args:
objs (seq[HasProps or Document]) :

Returns:
bool

'''
"""
# Move the import outside the function for improved efficiency if function is called multiple times
# It is safe as Widget is only used for isinstance and not mutated.
from ..models.widgets import Widget
return _any(all_objs, lambda obj: isinstance(obj, Widget)) or _ext_use_widgets(all_objs)

# Fast-path check: build set of types only once
widget_type = Widget
for obj in all_objs:
if isinstance(obj, widget_type):
return True
return _ext_use_widgets(all_objs)

def _model_requires_mathjax(model: HasProps) -> bool:
"""Whether a model requires MathJax to be loaded
Expand Down Expand Up @@ -465,6 +481,7 @@ def _ext_use_tables(all_objs: set[HasProps]) -> bool:
return _query_extensions(all_objs, lambda cls: issubclass(cls, TableWidget))

def _ext_use_widgets(all_objs: set[HasProps]) -> bool:
# Move the import outside the function for efficiency
from ..models.widgets import Widget
return _query_extensions(all_objs, lambda cls: issubclass(cls, Widget))

Expand Down