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

Improve detection of comms in vscode and colab #4115

Merged
merged 1 commit into from
Nov 14, 2022
Merged
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
24 changes: 17 additions & 7 deletions panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class _config(_base_config):
_admin = param.Boolean(default=False, doc="Whether the admin panel was enabled.")

_comms = param.ObjectSelector(
default='default', objects=['default', 'ipywidgets', 'vscode', 'colab'], doc="""
default=None, objects=[None, 'default', 'ipywidgets', 'vscode', 'colab'], doc="""
Whether to render output in Jupyter with the default Jupyter
extension or use the jupyter_bokeh ipywidget model.""")

Expand Down Expand Up @@ -601,6 +601,8 @@ def __call__(self, *args, **params):

from .io.notebook import load_notebook

self._detect_comms(params)

newly_loaded = [arg for arg in args if arg not in panel_extension._loaded_extensions]
if loaded and newly_loaded:
self.param.warning(
Expand Down Expand Up @@ -637,7 +639,18 @@ def __call__(self, *args, **params):
load_notebook(config.inline)
panel_extension._loaded = True

if config.notifications:
display(state.notifications) # noqa

if config.load_entry_points:
self._load_entry_points()

def _detect_comms(self, params):
if 'comms' in params:
config.comms = params.pop("comms")
return

if config.comms is not None:
return

# Try to detect environment so that we can enable comms
Expand All @@ -648,18 +661,15 @@ def __call__(self, *args, **params):
except ImportError:
pass

# Check if we're running in VSCode
if "VSCODE_PID" in os.environ:
config.comms = "vscode"
return

if "pyodide" in sys.modules:
config.comms = "ipywidgets"
return

if config.notifications:
display(state.notifications) # noqa

if config.load_entry_points:
self._load_entry_points()
config.comms = "default"

def _apply_signatures(self):
from inspect import Parameter, Signature
Expand Down