Skip to content

Commit

Permalink
Merge pull request #4376 from mpacer/update_json_configd
Browse files Browse the repository at this point in the history
surface config.d nbserver_extensions to the NotebookApp config object
  • Loading branch information
minrk authored Feb 25, 2019
2 parents 906406a + 134c8b6 commit 46ee18b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
31 changes: 19 additions & 12 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,15 +1563,13 @@ def init_components(self):
# TODO: this should still check, but now we use bower, not git submodule
pass

def init_server_extensions(self):
"""Load any extensions specified by config.
def init_server_extension_config(self):
"""Consolidate server extensions specified by all configs.
Import the module, then call the load_jupyter_server_extension function,
if one exists.
The resulting list is stored on self.nbserver_extensions and updates config object.
The extension API is experimental, and may change in future releases.
"""

# TODO: Remove me in notebook 5.0
for modulename in self.server_extensions:
# Don't override disable state of the extension if it already exist
Expand All @@ -1590,15 +1588,23 @@ def init_server_extensions(self):
manager = ConfigManager(read_config_path=config_path)
section = manager.get(self.config_file_name)
extensions = section.get('NotebookApp', {}).get('nbserver_extensions', {})

for modulename, enabled in sorted(extensions.items()):
if modulename not in self.nbserver_extensions:
self.config.NotebookApp.nbserver_extensions.update({modulename: enabled})
self.nbserver_extensions.update({modulename: enabled})

for modulename, enabled in self.nbserver_extensions.items():
if modulename not in extensions:
# not present in `extensions` means it comes from Python config,
# so we need to add it.
# Otherwise, trust ConfigManager to have loaded it.
extensions[modulename] = enabled
def init_server_extensions(self):
"""Load any extensions specified by config.
for modulename, enabled in sorted(extensions.items()):
Import the module, then call the load_jupyter_server_extension function,
if one exists.
The extension API is experimental, and may change in future releases.
"""


for modulename, enabled in sorted(self.nbserver_extensions.items()):
if enabled:
try:
mod = importlib.import_module(modulename)
Expand Down Expand Up @@ -1656,6 +1662,7 @@ def initialize(self, argv=None):
if self._dispatching:
return
self.init_configurables()
self.init_server_extension_config()
self.init_components()
self.init_webapp()
self.init_terminals()
Expand Down
1 change: 1 addition & 0 deletions notebook/tests/test_serverextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def test_merge_config(self):
toggle_serverextension_python('mockext_both', enabled=False, user=True)

app = NotebookApp(nbserver_extensions={'mockext_py': True})
app.init_server_extension_config()
app.init_server_extensions()

assert mock_user.loaded
Expand Down

0 comments on commit 46ee18b

Please sign in to comment.