##// END OF EJS Templates
Merge pull request #5593 from minrk/no-kernel-argv...
Thomas Kluyver -
r16381:619bd44f merge
parent child Browse files
Show More
@@ -1,23 +1,11 b''
1 # coding: utf-8
1 # coding: utf-8
2 """A tornado based IPython notebook server.
2 """A tornado based IPython notebook server."""
3
3
4 Authors:
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5
6
6 * Brian Granger
7 """
8 from __future__ import print_function
7 from __future__ import print_function
9 #-----------------------------------------------------------------------------
10 # Copyright (C) 2013 The IPython Development Team
11 #
12 # Distributed under the terms of the BSD License. The full license is in
13 # the file COPYING, distributed as part of this software.
14 #-----------------------------------------------------------------------------
15
8
16 #-----------------------------------------------------------------------------
17 # Imports
18 #-----------------------------------------------------------------------------
19
20 # stdlib
21 import errno
9 import errno
22 import io
10 import io
23 import json
11 import json
@@ -33,7 +21,6 b' import time'
33 import webbrowser
21 import webbrowser
34
22
35
23
36 # Third party
37 # check for pyzmq 2.1.11
24 # check for pyzmq 2.1.11
38 from IPython.utils.zmqrelated import check_for_zmq
25 from IPython.utils.zmqrelated import check_for_zmq
39 check_for_zmq('2.1.11', 'IPython.html')
26 check_for_zmq('2.1.11', 'IPython.html')
@@ -61,7 +48,6 b' if version_info < (3,1,0):'
61 from tornado import httpserver
48 from tornado import httpserver
62 from tornado import web
49 from tornado import web
63
50
64 # Our own libraries
65 from IPython.html import DEFAULT_STATIC_FILES_PATH
51 from IPython.html import DEFAULT_STATIC_FILES_PATH
66 from .base.handlers import Template404
52 from .base.handlers import Template404
67 from .log import log_request
53 from .log import log_request
@@ -75,15 +61,12 b' from .base.handlers import AuthenticatedFileHandler, FileFindHandler'
75
61
76 from IPython.config import Config
62 from IPython.config import Config
77 from IPython.config.application import catch_config_error, boolean_flag
63 from IPython.config.application import catch_config_error, boolean_flag
78 from IPython.core.application import BaseIPythonApplication
64 from IPython.core.application import (
79 from IPython.core.profiledir import ProfileDir
65 BaseIPythonApplication, base_flags, base_aliases,
80 from IPython.consoleapp import IPythonConsoleApp
81 from IPython.kernel import swallow_argv
82 from IPython.kernel.zmq.session import default_secure
83 from IPython.kernel.zmq.kernelapp import (
84 kernel_flags,
85 kernel_aliases,
86 )
66 )
67 from IPython.core.profiledir import ProfileDir
68 from IPython.kernel import KernelManager
69 from IPython.kernel.zmq.session import default_secure, Session
87 from IPython.nbformat.sign import NotebookNotary
70 from IPython.nbformat.sign import NotebookNotary
88 from IPython.utils.importstring import import_item
71 from IPython.utils.importstring import import_item
89 from IPython.utils import submodule
72 from IPython.utils import submodule
@@ -248,11 +231,15 b' class NbserverListApp(BaseIPythonApplication):'
248 # Aliases and Flags
231 # Aliases and Flags
249 #-----------------------------------------------------------------------------
232 #-----------------------------------------------------------------------------
250
233
251 flags = dict(kernel_flags)
234 flags = dict(base_flags)
252 flags['no-browser']=(
235 flags['no-browser']=(
253 {'NotebookApp' : {'open_browser' : False}},
236 {'NotebookApp' : {'open_browser' : False}},
254 "Don't open the notebook in a browser after startup."
237 "Don't open the notebook in a browser after startup."
255 )
238 )
239 flags['pylab']=(
240 {'NotebookApp' : {'pylab' : 'warn'}},
241 "DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib."
242 )
256 flags['no-mathjax']=(
243 flags['no-mathjax']=(
257 {'NotebookApp' : {'enable_mathjax' : False}},
244 {'NotebookApp' : {'enable_mathjax' : False}},
258 """Disable MathJax
245 """Disable MathJax
@@ -270,12 +257,7 b" flags.update(boolean_flag('script', 'FileNotebookManager.save_script',"
270 'Auto-save a .py script everytime the .ipynb notebook is saved',
257 'Auto-save a .py script everytime the .ipynb notebook is saved',
271 'Do not auto-save .py scripts for every notebook'))
258 'Do not auto-save .py scripts for every notebook'))
272
259
273 # the flags that are specific to the frontend
260 aliases = dict(base_aliases)
274 # these must be scrubbed before being passed to the kernel,
275 # or it will raise an error on unrecognized flags
276 notebook_flags = ['no-browser', 'no-mathjax', 'script', 'no-script']
277
278 aliases = dict(kernel_aliases)
279
261
280 aliases.update({
262 aliases.update({
281 'ip': 'NotebookApp.ip',
263 'ip': 'NotebookApp.ip',
@@ -286,15 +268,9 b' aliases.update({'
286 'certfile': 'NotebookApp.certfile',
268 'certfile': 'NotebookApp.certfile',
287 'notebook-dir': 'NotebookApp.notebook_dir',
269 'notebook-dir': 'NotebookApp.notebook_dir',
288 'browser': 'NotebookApp.browser',
270 'browser': 'NotebookApp.browser',
271 'pylab': 'NotebookApp.pylab',
289 })
272 })
290
273
291 # remove ipkernel flags that are singletons, and don't make sense in
292 # multi-kernel evironment:
293 aliases.pop('f', None)
294
295 notebook_aliases = [u'port', u'port-retries', u'ip', u'keyfile', u'certfile',
296 u'notebook-dir', u'profile', u'profile-dir', 'browser']
297
298 #-----------------------------------------------------------------------------
274 #-----------------------------------------------------------------------------
299 # NotebookApp
275 # NotebookApp
300 #-----------------------------------------------------------------------------
276 #-----------------------------------------------------------------------------
@@ -310,9 +286,13 b' class NotebookApp(BaseIPythonApplication):'
310 HTML5/Javascript Notebook client.
286 HTML5/Javascript Notebook client.
311 """
287 """
312 examples = _examples
288 examples = _examples
289 aliases = aliases
290 flags = flags
313
291
314 classes = IPythonConsoleApp.classes + [MappingKernelManager, NotebookManager,
292 classes = [
315 FileNotebookManager, NotebookNotary]
293 KernelManager, ProfileDir, Session, MappingKernelManager,
294 NotebookManager, FileNotebookManager, NotebookNotary,
295 ]
316 flags = Dict(flags)
296 flags = Dict(flags)
317 aliases = Dict(aliases)
297 aliases = Dict(aliases)
318
298
@@ -524,6 +504,23 b' class NotebookApp(BaseIPythonApplication):'
524 notebook_dir = Unicode(py3compat.getcwd(), config=True,
504 notebook_dir = Unicode(py3compat.getcwd(), config=True,
525 help="The directory to use for notebooks and kernels."
505 help="The directory to use for notebooks and kernels."
526 )
506 )
507
508 pylab = Unicode('disabled', config=True,
509 help="""
510 DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
511 """
512 )
513 def _pylab_changed(self, name, old, new):
514 """when --pylab is specified, display a warning and exit"""
515 if new != 'warn':
516 backend = ' %s' % new
517 else:
518 backend = ''
519 self.log.error("Support for specifying --pylab on the command line has been removed.")
520 self.log.error(
521 "Please use `%pylab{0}` or `%matplotlib{0}` in the notebook itself.".format(backend)
522 )
523 self.exit(1)
527
524
528 def _notebook_dir_changed(self, name, old, new):
525 def _notebook_dir_changed(self, name, old, new):
529 """Do a bit of validation of the notebook dir."""
526 """Do a bit of validation of the notebook dir."""
@@ -561,16 +558,7 b' class NotebookApp(BaseIPythonApplication):'
561
558
562 def init_kernel_argv(self):
559 def init_kernel_argv(self):
563 """construct the kernel arguments"""
560 """construct the kernel arguments"""
564 # Scrub frontend-specific flags
561 self.kernel_argv = []
565 self.kernel_argv = swallow_argv(self.argv, notebook_aliases, notebook_flags)
566 if any(arg.startswith(u'--pylab') for arg in self.kernel_argv):
567 self.log.warn('\n '.join([
568 "Starting all kernels in pylab mode is not recommended,",
569 "and will be disabled in a future release.",
570 "Please use the %matplotlib magic to enable matplotlib instead.",
571 "pylab implies many imports, which can have confusing side effects",
572 "and harm the reproducibility of your notebooks.",
573 ]))
574 # Kernel should inherit default config file from frontend
562 # Kernel should inherit default config file from frontend
575 self.kernel_argv.append("--IPKernelApp.parent_appname='%s'" % self.name)
563 self.kernel_argv.append("--IPKernelApp.parent_appname='%s'" % self.name)
576 # Kernel should get *absolute* path to profile directory
564 # Kernel should get *absolute* path to profile directory
General Comments 0
You need to be logged in to leave comments. Login now