Skip to content

Commit 0f015c4

Browse files
mpacerkevin-bates
authored andcommitted
surface config.d nbserver_extensions to the NotebookApp config object
- separates nbserver_extension config loading into new init_server_extension_config method - adds init_server_extension_config to the initialize funciton before the init_webapp call - adds nbserver_extension configuration found in config.d files (by the BaseJSONConfigLoader) to both the underlying NotebookApp config object and the self.nbserver_extensions value - makes self.nbserver_extensions the canonical location for identifying all nbserver_extensions rather than temporary extensions variable
1 parent 95d3dac commit 0f015c4

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

jupyter_server/serverapp.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,15 +1442,13 @@ def init_components(self):
14421442
# TODO: this should still check, but now we use bower, not git submodule
14431443
pass
14441444

1445-
def init_server_extensions(self):
1446-
"""Load any extensions specified by config.
1447-
1448-
Import the module, then call the load_jupyter_server_extension function,
1449-
if one exists.
1445+
def init_server_extension_config(self):
1446+
"""Consolidate server extensions specified by all configs.
14501447
1448+
The resulting list is stored on self.nbserver_extensions and updates config object.
1449+
14511450
The extension API is experimental, and may change in future releases.
14521451
"""
1453-
14541452
# Load server extensions with ConfigManager.
14551453
# This enables merging on keys, which we want for extension enabling.
14561454
# Regular config loading only merges at the class level,
@@ -1462,15 +1460,21 @@ def init_server_extensions(self):
14621460
manager = ConfigManager(read_config_path=config_path)
14631461
section = manager.get(self.config_file_name)
14641462
extensions = section.get('ServerApp', {}).get('jpserver_extensions', {})
1463+
1464+
for modulename, enabled in sorted(extensions.items()):
1465+
if modulename not in self.jpserver_extensions:
1466+
self.config.ServerApp.jpserver_extensions.update({modulename: enabled})
1467+
self.jpserver_extensions.update({modulename: enabled})
14651468

1466-
for modulename, enabled in self.jpserver_extensions.items():
1467-
if modulename not in extensions:
1468-
# not present in `extensions` means it comes from Python config,
1469-
# so we need to add it.
1470-
# Otherwise, trust ConfigManager to have loaded it.
1471-
extensions[modulename] = enabled
1469+
def init_server_extensions(self):
1470+
"""Load any extensions specified by config.
14721471
1473-
for modulename, enabled in sorted(extensions.items()):
1472+
Import the module, then call the load_jupyter_server_extension function,
1473+
if one exists.
1474+
1475+
The extension API is experimental, and may change in future releases.
1476+
"""
1477+
for modulename, enabled in sorted(self.jpserver_extensions.items()):
14741478
if enabled:
14751479
try:
14761480
mod = importlib.import_module(modulename)
@@ -1538,6 +1542,7 @@ def initialize(self, argv=None, load_extensions=True):
15381542
if self._dispatching:
15391543
return
15401544
self.init_configurables()
1545+
self.init_server_extension_config()
15411546
self.init_components()
15421547
self.init_webapp()
15431548
self.init_terminals()

jupyter_server/tests/test_extensions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ def test_merge_config(self):
137137
toggle_serverextension_python('mockext_both', enabled=True, user=False)
138138
toggle_serverextension_python('mockext_both', enabled=False, user=True)
139139

140+
<<<<<<< HEAD:jupyter_server/tests/test_extensions.py
140141
app = ServerApp(jpserver_extensions={'mockext_py': True})
142+
=======
143+
app = NotebookApp(nbserver_extensions={'mockext_py': True})
144+
app.init_server_extension_config()
145+
>>>>>>> 134c8b6c0... surface config.d nbserver_extensions to the NotebookApp config object:notebook/tests/test_serverextensions.py
141146
app.init_server_extensions()
142147

143148
assert mock_user.loaded

0 commit comments

Comments
 (0)