From 5d1a595ba2b08612f235762b42db97e86b16f8e7 Mon Sep 17 00:00:00 2001 From: M Pacer Date: Wed, 30 Jan 2019 12:50:48 -0800 Subject: [PATCH] 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 --- notebook/notebookapp.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 05e44cf29fa..2a43ec96638 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -1539,15 +1539,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 @@ -1566,15 +1564,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) @@ -1632,6 +1638,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()