Skip to content

Commit 134c8b6

Browse files
committed
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 c33130d commit 134c8b6

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

notebook/notebookapp.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,15 +1539,13 @@ def init_components(self):
15391539
# TODO: this should still check, but now we use bower, not git submodule
15401540
pass
15411541

1542-
def init_server_extensions(self):
1543-
"""Load any extensions specified by config.
1542+
def init_server_extension_config(self):
1543+
"""Consolidate server extensions specified by all configs.
15441544
1545-
Import the module, then call the load_jupyter_server_extension function,
1546-
if one exists.
1545+
The resulting list is stored on self.nbserver_extensions and updates config object.
15471546
15481547
The extension API is experimental, and may change in future releases.
15491548
"""
1550-
15511549
# TODO: Remove me in notebook 5.0
15521550
for modulename in self.server_extensions:
15531551
# Don't override disable state of the extension if it already exist
@@ -1566,15 +1564,23 @@ def init_server_extensions(self):
15661564
manager = ConfigManager(read_config_path=config_path)
15671565
section = manager.get(self.config_file_name)
15681566
extensions = section.get('NotebookApp', {}).get('nbserver_extensions', {})
1567+
1568+
for modulename, enabled in sorted(extensions.items()):
1569+
if modulename not in self.nbserver_extensions:
1570+
self.config.NotebookApp.nbserver_extensions.update({modulename: enabled})
1571+
self.nbserver_extensions.update({modulename: enabled})
15691572

1570-
for modulename, enabled in self.nbserver_extensions.items():
1571-
if modulename not in extensions:
1572-
# not present in `extensions` means it comes from Python config,
1573-
# so we need to add it.
1574-
# Otherwise, trust ConfigManager to have loaded it.
1575-
extensions[modulename] = enabled
1573+
def init_server_extensions(self):
1574+
"""Load any extensions specified by config.
15761575
1577-
for modulename, enabled in sorted(extensions.items()):
1576+
Import the module, then call the load_jupyter_server_extension function,
1577+
if one exists.
1578+
1579+
The extension API is experimental, and may change in future releases.
1580+
"""
1581+
1582+
1583+
for modulename, enabled in sorted(self.nbserver_extensions.items()):
15781584
if enabled:
15791585
try:
15801586
mod = importlib.import_module(modulename)
@@ -1632,6 +1638,7 @@ def initialize(self, argv=None):
16321638
if self._dispatching:
16331639
return
16341640
self.init_configurables()
1641+
self.init_server_extension_config()
16351642
self.init_components()
16361643
self.init_webapp()
16371644
self.init_terminals()

notebook/tests/test_serverextensions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def test_merge_config(self):
147147
toggle_serverextension_python('mockext_both', enabled=False, user=True)
148148

149149
app = NotebookApp(nbserver_extensions={'mockext_py': True})
150+
app.init_server_extension_config()
150151
app.init_server_extensions()
151152

152153
assert mock_user.loaded

0 commit comments

Comments
 (0)