Skip to content

Commit

Permalink
Make import lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 8, 2021
1 parent 241d2a5 commit fdad5cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion panel/models/__init__.py
Expand Up @@ -14,7 +14,6 @@
from .reactive_html import ReactiveHTML # noqa
from .state import State # noqa
from .tabulator import DataTabulator # noqa
from .terminal import Terminal # noqa
from .trend import TrendIndicator # noqa
from .widgets import ( # noqa
Audio, FileDownload, Player, Progress, SingleSelect, Video, VideoStream
Expand Down
10 changes: 7 additions & 3 deletions panel/tests/widgets/test_base.py
Expand Up @@ -5,15 +5,19 @@
from panel.layout import Row
from panel.links import CallbackGenerator
from panel.widgets import (
CompositeWidget, Dial, FileDownload, FloatSlider, TextInput, ToggleGroup, Widget
CompositeWidget, Dial, FileDownload, FloatSlider, TextInput,
Terminal, ToggleGroup, Widget
)
from panel.widgets.tables import BaseTable
from panel.tests.util import check_layoutable_properties

excluded = (
BaseTable, CompositeWidget, Dial, FileDownload, ToggleGroup, Terminal
)

all_widgets = [
w for w in param.concrete_descendents(Widget).values()
if not w.__name__.startswith('_') and
not issubclass(w, (CompositeWidget, BaseTable, FileDownload, ToggleGroup, Dial))
if not w.__name__.startswith('_') and not issubclass(w, excluded)
]

@pytest.mark.parametrize('widget', all_widgets)
Expand Down
11 changes: 7 additions & 4 deletions panel/widgets/terminal.py
Expand Up @@ -14,8 +14,10 @@

import param

from pyviz_comms import JupyterComm

from ..io.callbacks import PeriodicCallback
from ..models import Terminal as _BkTerminal
from ..util import lazy_load
from .base import Widget


Expand Down Expand Up @@ -224,9 +226,6 @@ class Terminal(Widget):
"write_to_console": None,
}

# Set the Bokeh model to use
_widget_type = _BkTerminal

def __init__(self, output=None, **params):
params['_output'] = output = output or ""
params['clear'] = self._clear
Expand All @@ -251,6 +250,10 @@ def write(self, __s):
return len(self.output)

def _get_model(self, doc, root=None, parent=None, comm=None):
if self._widget_type is None:
self._widget_type = lazy_load(
'panel.models.terminal', 'Terminal', isinstance(comm, JupyterComm)
)
model = super()._get_model(doc, root, parent, comm)
model.output = self.output
return model
Expand Down

0 comments on commit fdad5cc

Please sign in to comment.