From e86d80e84a80cbe156c4547310f69178aefeb154 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 2 Dec 2014 15:51:30 -0800 Subject: [PATCH 1/3] Add support for notebook server extensions As some people may be tiring of my pointing out, it seems strange that we have extension points for the JS and the kernel, but none for the notebook server. For cite2c, I want to add a handler which can serve a directory of style files for use by the nbextension part. --- IPython/html/notebookapp.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index 291094ce2..829dc0ec5 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -9,6 +9,7 @@ from __future__ import print_function import base64 import datetime import errno +import importlib import io import json import logging @@ -709,6 +710,10 @@ class NotebookApp(BaseIPythonApplication): self.config.FileContentsManager.root_dir = new self.config.MappingKernelManager.root_dir = new + extensions = List(Unicode(), config=True, + help="Python modules to load as notebook server extensions" + ) + def parse_command_line(self, argv=None): super(NotebookApp, self).parse_command_line(argv) @@ -915,6 +920,22 @@ class NotebookApp(BaseIPythonApplication): elif status == 'unclean': self.log.warn("components submodule unclean, you may see 404s on static/components") self.log.warn("run `setup.py submodule` or `git submodule update` to update") + + def init_extensions(self): + """Load any extensions specified by config. + + Import the module, then call the load_jupyter_server_extension function, + if one exists. + """ + for modulename in self.extensions: + try: + mod = importlib.import_module(modulename) + func = getattr(mod, 'load_jupyter_server_extension', None) + if func is not None: + func(self) + except Exception: + self.log.warn("Error loading server extension %s", modulename, + exc_info=True) @catch_config_error def initialize(self, argv=None): @@ -926,6 +947,7 @@ class NotebookApp(BaseIPythonApplication): self.init_webapp() self.init_terminals() self.init_signal() + self.init_extensions() def cleanup_kernels(self): """Shutdown all kernels. From 7e7d3d1f250d6932fda6ca6b95288a6c5e6a83fe Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 2 Dec 2014 16:31:58 -0800 Subject: [PATCH 2/3] Rename extensions -> server_extensions --- IPython/html/notebookapp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index 829dc0ec5..80db09609 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -710,7 +710,7 @@ class NotebookApp(BaseIPythonApplication): self.config.FileContentsManager.root_dir = new self.config.MappingKernelManager.root_dir = new - extensions = List(Unicode(), config=True, + server_extensions = List(Unicode(), config=True, help="Python modules to load as notebook server extensions" ) @@ -921,13 +921,13 @@ class NotebookApp(BaseIPythonApplication): self.log.warn("components submodule unclean, you may see 404s on static/components") self.log.warn("run `setup.py submodule` or `git submodule update` to update") - def init_extensions(self): + def init_server_extensions(self): """Load any extensions specified by config. Import the module, then call the load_jupyter_server_extension function, if one exists. """ - for modulename in self.extensions: + for modulename in self.server_extensions: try: mod = importlib.import_module(modulename) func = getattr(mod, 'load_jupyter_server_extension', None) @@ -947,7 +947,7 @@ class NotebookApp(BaseIPythonApplication): self.init_webapp() self.init_terminals() self.init_signal() - self.init_extensions() + self.init_server_extensions() def cleanup_kernels(self): """Shutdown all kernels. From 0f2f14556c70e52b52d1407378d455d2b70a8cf3 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 11 Dec 2014 11:52:24 -0800 Subject: [PATCH 3/3] Note that extension API is experimental --- IPython/html/notebookapp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index 80db09609..36e0f2ec0 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -711,7 +711,8 @@ class NotebookApp(BaseIPythonApplication): self.config.MappingKernelManager.root_dir = new server_extensions = List(Unicode(), config=True, - help="Python modules to load as notebook server extensions" + help=("Python modules to load as notebook server extensions. " + "This is an experimental API, and may change in future releases.") ) def parse_command_line(self, argv=None): @@ -926,6 +927,8 @@ class NotebookApp(BaseIPythonApplication): 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 in self.server_extensions: try: