Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence EMPTY_LAYOUT warnings #4056

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
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
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