Skip to content

Commit

Permalink
Silence EMPTY_LAYOUT warnings (#4056)
Browse files Browse the repository at this point in the history
* silence EMPTY_LAYOUT bokeh warnings

* add a test
  • Loading branch information
maximlt authored Oct 25, 2022
1 parent f083d88 commit c2933d3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions panel/command/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from bokeh.application.handlers.function import FunctionHandler
from bokeh.command.subcommands.serve import Serve as _BkServe
from bokeh.command.util import build_single_handler_applications
from bokeh.core.validation import silence
from bokeh.core.validation.warnings import EMPTY_LAYOUT
from bokeh.server.contexts import ApplicationContext
from tornado.ioloop import PeriodicCallback
from tornado.web import StaticFileHandler
Expand Down Expand Up @@ -490,3 +492,9 @@ def customize_kwargs(self, args, server_kwargs):
kwargs['cookie_secret'] = config.cookie_secret

return kwargs

def invoke(self, args):
# Empty layout are valid and the Bokeh warning is silenced as usually
# not relevant to Panel users.
silence(EMPTY_LAYOUT, True)
super().invoke(args)
5 changes: 5 additions & 0 deletions panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
from bokeh.application.handlers.function import FunctionHandler
from bokeh.command.util import build_single_handler_application
from bokeh.core.templates import AUTOLOAD_JS
from bokeh.core.validation import silence
from bokeh.core.validation.warnings import EMPTY_LAYOUT
from bokeh.embed.bundle import Script
from bokeh.embed.elements import (
html_page_for_render_items, script_for_render_items,
Expand Down Expand Up @@ -682,6 +684,9 @@ def serve(
kwargs: dict
Additional keyword arguments to pass to Server instance
"""
# Empty layout are valid and the Bokeh warning is silenced as usually
# not relevant to Panel users.
silence(EMPTY_LAYOUT, True)
kwargs = dict(kwargs, **dict(
port=port, address=address, websocket_origin=websocket_origin,
loop=loop, show=show, start=start, title=title, verbose=verbose,
Expand Down
28 changes: 28 additions & 0 deletions panel/tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import datetime as dt
import logging
import os
import pathlib
import time
Expand Down Expand Up @@ -911,3 +912,30 @@ def app():
time.sleep(0.5)

assert len(exceptions) == 1


def test_server_no_warning_empty_layout(port, caplog):

bk_logger = logging.getLogger('bokeh')
old_level = bk_logger.level
old_propagate = bk_logger.propagate
try:
# Test pretty dependent on how Bokeh sets up its logging system
bk_logger.propagate = True
bk_logger.setLevel(logging.WARNING)

app = Row()

serve(app, port=port, threaded=True, show=False)

# Wait for server to start
time.sleep(1)
requests.get(f"http://localhost:{port}")
time.sleep(1)

for rec in caplog.records:
if rec.levelname == 'WARNING':
assert 'EMPTY_LAYOUT' not in rec.message
finally:
bk_logger.setLevel(old_level)
bk_logger.propagate = old_propagate

0 comments on commit c2933d3

Please sign in to comment.