Skip to content

Commit

Permalink
Support jupyter server root_dir with lab extension
Browse files Browse the repository at this point in the history
Jupyter sends path relative to the root_dir which can be different from the cwd. This commit fixes the lab extension for panel preview to account for root_dir.

Reference: holoviz#3170
  • Loading branch information
govinda18 committed Feb 3, 2022
1 parent 5df060d commit 65dc5fa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions panel/io/jupyter_server_extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from urllib.parse import urljoin

import tornado
import os

from bokeh.command.util import build_single_handler_application
from bokeh.embed.bundle import extension_dirs
Expand Down Expand Up @@ -65,6 +66,17 @@ class ServerApplicationProxy:
def __init__(self, app, **kw):
self._app = app

@property
def root_dir(self):
"""
Gets the root directory of the jupyter server app
This is useful as the path sent received by the handler
may be different from the root dir.
Reference: https://github.com/holoviz/panel/issues/3170
"""
return self._app.settings['server_root_dir']

def __getattr__(self, key):
return getattr(self._app, key)

Expand All @@ -81,6 +93,7 @@ def initialize(self, *args, **kws):
pass

async def get(self, path, *args, **kwargs):
path = os.path.join(self.application.root_dir, path)
if path in _APPS:
app, context = _APPS[path]
else:
Expand Down Expand Up @@ -122,6 +135,7 @@ def initialize(self, *args, **kwargs):
pass

async def open(self, path, *args, **kwargs):
path = os.path.join(self.application.root_dir, path)
_, context = _APPS[path]

token = self._token
Expand Down

0 comments on commit 65dc5fa

Please sign in to comment.