Skip to content

Commit 7b9c024

Browse files
authored
Delay list -> dict conversation to end (#192)
1 parent 04fcf0e commit 7b9c024

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

jupyterlab_server/config.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def get_page_config(labextensions_path, app_settings_dir=None, logger=None):
9797
# Convert lists to dicts
9898
for key in [disabled_key, "deferredExtensions"]:
9999
if key in data:
100-
data[key] = dict((key, True) for key in data[key])
100+
data[key] = dict((k, True) for k in data[key])
101101

102102
recursive_update(page_config, data)
103103

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

170-
# Convert dictionaries to lists to give to the front end
171-
for (key, value) in page_config.items():
172-
173-
if isinstance(value, dict):
174-
page_config[key] = [subkey for subkey in value if value[subkey]]
175-
176170
return page_config
177171

178172

jupyterlab_server/handlers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Module globals
2626
# -----------------------------------------------------------------------------
2727

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

3030
DEFAULT_TEMPLATE = template.Template("""
3131
<!DOCTYPE html>
@@ -125,6 +125,13 @@ def get_page_config(self):
125125
if page_config_hook:
126126
page_config = page_config_hook(self, page_config)
127127

128+
# Convert dictionaries to lists to give to the front end
129+
# copy first, so that we don't have converted values in page_copy that we have a ref to
130+
page_config = page_config.copy()
131+
for (key, value) in page_config.items():
132+
if isinstance(value, dict):
133+
page_config[key] = [subkey for subkey in value if value[subkey]]
134+
128135
return page_config
129136

130137
@web.authenticated

jupyterlab_server/pytest_plugin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ def _make_labserver_extension_app(**kwargs):
112112
data = dict(name=target_name, jupyterlab=dict(extension=True))
113113
json.dump(data, fid)
114114

115+
# Disable an extension in page config
116+
app_page_config = pjoin(app_settings_dir, 'page_config.json')
117+
with open(app_page_config, mode="w", encoding='utf-8') as fid:
118+
json.dump({
119+
"disabledExtensions": {
120+
"@foo/bar:plugin": True
121+
}
122+
}, fid)
123+
115124
# Copy the overrides file.
116125
src = pjoin(
117126
os.path.abspath(os.path.dirname(__file__)),

jupyterlab_server/tests/test_labapp.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Basic tests for the lab handlers.
22
"""
33

4+
import json
45
import pytest
6+
import re
57
import tornado
68

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

3032

33+
async def test_page_config(labserverapp, jp_fetch):
34+
settings = labserverapp.serverapp.web_app.settings
35+
page_config = settings.setdefault('page_config_data', {})
36+
# In labserverapp fixture, we dump a page_config file that also disables "@foo/bar:plugin"
37+
# Here we check that we correctly merge those settings with page_config_data in settings
38+
page_config.setdefault("disabledExtensions", {"@acme/paint:plugin": True})
39+
r = await jp_fetch('lab', 'jlab_test_notebooks')
40+
assert r.code == 200
41+
# Check that the lab template is loaded
42+
html = r.body.decode()
43+
m = re.search(
44+
r'<script id="jupyter-config-data" type="application/json">(?P<page_config>.*?)</script>',
45+
html,
46+
re.MULTILINE | re.DOTALL
47+
)
48+
page_config = json.loads(m.group("page_config"))
49+
assert sorted(page_config['disabledExtensions']) == ["@acme/paint:plugin", "@foo/bar:plugin"]
50+
3151
async def test_notebook_handler(notebooks, jp_fetch):
3252
for nbpath in notebooks:
3353
r = await jp_fetch('lab', nbpath)

0 commit comments

Comments
 (0)