Skip to content

Commit

Permalink
Add support for bokeh 2.4 (#2644)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Aug 18, 2021
1 parent 48ed9b6 commit 7d07a3b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
36 changes: 29 additions & 7 deletions panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from tornado.wsgi import WSGIContainer

# Internal imports
from ..util import edit_readonly
from ..util import bokeh_version, edit_readonly
from .reload import autoreload_watcher
from .resources import BASE_TEMPLATE, Resources, bundle_resources
from .state import state
Expand Down Expand Up @@ -289,11 +289,17 @@ def modify_document(self, doc):
# stored modules are used to provide correct paths to
# custom models resolver.
sys.modules[module.__name__] = module
doc._modules.append(module)
if bokeh_version >= '2.4.0':
doc.modules._modules.append(module)

else:
doc._modules.append(module)

old_doc = curdoc()
bk_set_curdoc(doc)
old_io = self._monkeypatch_io()

if bokeh_version < '2.4.0':
self._monkeypatch_io()

if config.autoreload:
set_curdoc(doc)
Expand All @@ -306,7 +312,11 @@ def post_check():
# otherwise it will erroneously complain that there is
# a memory leak
if config.autoreload:
newdoc._modules = []
if bokeh_version >= '2.4.0':
newdoc.modules._modules = []
else:
newdoc._modules = []

# script is supposed to edit the doc not replace it
if newdoc is not doc:
raise RuntimeError("%s at '%s' replaced the output document" % (self._origin, self._runner.path))
Expand All @@ -317,7 +327,11 @@ def handle_exception(handler, e):

# Clean up
del sys.modules[module.__name__]
doc._modules.remove(module)

if hasattr(doc, 'modules'):
doc.modules._modules.remove(module)
else:
doc._modules.remove(module)
bokeh.application.handlers.code_runner.handle_exception = handle_exception
tb = html.escape(traceback.format_exc())

Expand All @@ -329,9 +343,17 @@ def handle_exception(handler, e):

if config.autoreload:
bokeh.application.handlers.code_runner.handle_exception = handle_exception
self._runner.run(module, post_check)

if bokeh_version >= '2.4.0':
from bokeh.application.handlers.code import _monkeypatch_io, patch_curdoc
with _monkeypatch_io(self._loggers):
with patch_curdoc(doc):
self._runner.run(module, post_check)
else:
self._runner.run(module, post_check)
finally:
self._unmonkeypatch_io(old_io)
if bokeh_version < '2.4.0':
self._unmonkeypatch_io()
bk_set_curdoc(old_doc)

CodeHandler.modify_document = modify_document
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def run(self):
########## dependencies ##########

install_requires = [
'bokeh >=2.3.0,<2.4.0',
'bokeh >=2.3.0,<2.5.0',
'param >=1.10.0',
'pyviz_comms >=0.7.4',
'markdown',
Expand Down

0 comments on commit 7d07a3b

Please sign in to comment.