Skip to content

Commit

Permalink
Delay list -> dict conversation to end (jupyterlab#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
vidartf authored Dec 22, 2021
1 parent 04fcf0e commit 7b9c024
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
8 changes: 1 addition & 7 deletions jupyterlab_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_page_config(labextensions_path, app_settings_dir=None, logger=None):
# Convert lists to dicts
for key in [disabled_key, "deferredExtensions"]:
if key in data:
data[key] = dict((key, True) for key in data[key])
data[key] = dict((k, True) for k in data[key])

recursive_update(page_config, data)

Expand Down Expand Up @@ -167,12 +167,6 @@ def get_page_config(labextensions_path, app_settings_dir=None, logger=None):
rollup_disabled.update(page_config.get(disabled_key, []))
page_config[disabled_key] = rollup_disabled

# Convert dictionaries to lists to give to the front end
for (key, value) in page_config.items():

if isinstance(value, dict):
page_config[key] = [subkey for subkey in value if value[subkey]]

return page_config


Expand Down
9 changes: 8 additions & 1 deletion jupyterlab_server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Module globals
# -----------------------------------------------------------------------------

MASTER_URL_PATTERN = '/(?P<mode>{}|doc)(?P<workspace>/workspaces/[a-zA-Z0-9\-\_]+)?(?P<tree>/tree/.*)?'
MASTER_URL_PATTERN = r'/(?P<mode>{}|doc)(?P<workspace>/workspaces/[a-zA-Z0-9\-\_]+)?(?P<tree>/tree/.*)?'

DEFAULT_TEMPLATE = template.Template("""
<!DOCTYPE html>
Expand Down Expand Up @@ -125,6 +125,13 @@ def get_page_config(self):
if page_config_hook:
page_config = page_config_hook(self, page_config)

# Convert dictionaries to lists to give to the front end
# copy first, so that we don't have converted values in page_copy that we have a ref to
page_config = page_config.copy()
for (key, value) in page_config.items():
if isinstance(value, dict):
page_config[key] = [subkey for subkey in value if value[subkey]]

return page_config

@web.authenticated
Expand Down
9 changes: 9 additions & 0 deletions jupyterlab_server/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ def _make_labserver_extension_app(**kwargs):
data = dict(name=target_name, jupyterlab=dict(extension=True))
json.dump(data, fid)

# Disable an extension in page config
app_page_config = pjoin(app_settings_dir, 'page_config.json')
with open(app_page_config, mode="w", encoding='utf-8') as fid:
json.dump({
"disabledExtensions": {
"@foo/bar:plugin": True
}
}, fid)

# Copy the overrides file.
src = pjoin(
os.path.abspath(os.path.dirname(__file__)),
Expand Down
20 changes: 20 additions & 0 deletions jupyterlab_server/tests/test_labapp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Basic tests for the lab handlers.
"""

import json
import pytest
import re
import tornado

from .utils import expected_http_error
Expand All @@ -28,6 +30,24 @@ async def test_lab_handler(notebooks, jp_fetch):
assert "JupyterLab Server Application" in html


async def test_page_config(labserverapp, jp_fetch):
settings = labserverapp.serverapp.web_app.settings
page_config = settings.setdefault('page_config_data', {})
# In labserverapp fixture, we dump a page_config file that also disables "@foo/bar:plugin"
# Here we check that we correctly merge those settings with page_config_data in settings
page_config.setdefault("disabledExtensions", {"@acme/paint:plugin": True})
r = await jp_fetch('lab', 'jlab_test_notebooks')
assert r.code == 200
# Check that the lab template is loaded
html = r.body.decode()
m = re.search(
r'<script id="jupyter-config-data" type="application/json">(?P<page_config>.*?)</script>',
html,
re.MULTILINE | re.DOTALL
)
page_config = json.loads(m.group("page_config"))
assert sorted(page_config['disabledExtensions']) == ["@acme/paint:plugin", "@foo/bar:plugin"]

async def test_notebook_handler(notebooks, jp_fetch):
for nbpath in notebooks:
r = await jp_fetch('lab', nbpath)
Expand Down

0 comments on commit 7b9c024

Please sign in to comment.