From ec0026bbf9561f28fe5dba9969b072dc0de2657a Mon Sep 17 00:00:00 2001 From: Timo Paulssen Date: Sat, 10 Dec 2011 16:16:34 +0100 Subject: [PATCH 1/3] use IPythons config subsystem to allow overrides to the tornado web app. --- IPython/frontend/html/notebook/notebookapp.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index e7a00c0cd..870bfb701 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -89,6 +89,10 @@ ipython notebook --port=5555 --ip=* # Listen on port 5555, all interfaces class NotebookWebApplication(web.Application): + settings = Dict(config=True, + help="Supply overrides for the tornado.web.Application, that the " + "IPython notebook uses.") + def __init__(self, ipython_app, kernel_manager, notebook_manager, log): handlers = [ (r"/", ProjectDashboardHandler), @@ -111,7 +115,11 @@ class NotebookWebApplication(web.Application): cookie_secret=os.urandom(1024), login_url="/login", ) - web.Application.__init__(self, handlers, **settings) + + # allow custom overrides for the tornado web app. + settings.update(self.settings) + + super(NotebookWebApplication, self).__init__(self, handlers, **settings) self.kernel_manager = kernel_manager self.log = log From 7fa16984cc10057de2058ba34c3d65c1617bf0c8 Mon Sep 17 00:00:00 2001 From: Timo Paulssen Date: Sat, 10 Dec 2011 18:49:41 +0100 Subject: [PATCH 2/3] this is how the configuration system is supposed to be used. --- IPython/frontend/html/notebook/notebookapp.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 870bfb701..a091725a4 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -89,11 +89,7 @@ ipython notebook --port=5555 --ip=* # Listen on port 5555, all interfaces class NotebookWebApplication(web.Application): - settings = Dict(config=True, - help="Supply overrides for the tornado.web.Application, that the " - "IPython notebook uses.") - - def __init__(self, ipython_app, kernel_manager, notebook_manager, log): + def __init__(self, ipython_app, kernel_manager, notebook_manager, log, settings_overrides): handlers = [ (r"/", ProjectDashboardHandler), (r"/login", LoginHandler), @@ -117,9 +113,9 @@ class NotebookWebApplication(web.Application): ) # allow custom overrides for the tornado web app. - settings.update(self.settings) + settings.update(settings_overrides) - super(NotebookWebApplication, self).__init__(self, handlers, **settings) + super(NotebookWebApplication, self).__init__(handlers, **settings) self.kernel_manager = kernel_manager self.log = log @@ -251,6 +247,10 @@ class NotebookApp(BaseIPythonApplication): help="Whether to prevent editing/execution of notebooks." ) + webapp_settings = Dict(config=True, + help="Supply overrides for the tornado.web.Application that the " + "IPython notebook uses.") + enable_mathjax = Bool(True, config=True, help="""Whether to enable MathJax for typesetting math/TeX @@ -323,7 +323,8 @@ class NotebookApp(BaseIPythonApplication): super(NotebookApp, self).initialize(argv) self.init_configurables() self.web_app = NotebookWebApplication( - self, self.kernel_manager, self.notebook_manager, self.log + self, self.kernel_manager, self.notebook_manager, self.log, + self.webapp_settings ) if self.certfile: ssl_options = dict(certfile=self.certfile) From eb51077b26ef25802dd14f25fdec2a4de088a095 Mon Sep 17 00:00:00 2001 From: Timo Paulssen Date: Sat, 10 Dec 2011 22:44:12 +0100 Subject: [PATCH 3/3] look for mathjax in the custom static path if it's supplied. --- IPython/frontend/html/notebook/notebookapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index a091725a4..8fc6e3fcf 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -272,7 +272,7 @@ class NotebookApp(BaseIPythonApplication): def _mathjax_url_default(self): if not self.enable_mathjax: return u'' - static_path = os.path.join(os.path.dirname(__file__), "static") + static_path = self.webapp_settings.get("static_path", os.path.join(os.path.dirname(__file__), "static")) if os.path.exists(os.path.join(static_path, 'mathjax', "MathJax.js")): self.log.info("Using local MathJax") return u"static/mathjax/MathJax.js"