From a2ec27ac519c10cdb71c6beb1ecc972566369f93 2014-08-30 09:26:51 From: Thomas Kluyver Date: 2014-08-30 09:26:51 Subject: [PATCH] Simplify kernel manager code --- diff --git a/IPython/kernel/kernelspec.py b/IPython/kernel/kernelspec.py index 46edf99..a0a81a1 100644 --- a/IPython/kernel/kernelspec.py +++ b/IPython/kernel/kernelspec.py @@ -9,6 +9,7 @@ pjoin = os.path.join from IPython.utils.path import get_ipython_dir from IPython.utils.py3compat import PY3 from IPython.utils.traitlets import HasTraits, List, Unicode, Dict, Any +from .launcher import make_ipkernel_cmd if os.name == 'nt': programdata = os.environ.get('PROGRAMDATA', None) @@ -107,9 +108,8 @@ class KernelSpecManager(HasTraits): The native kernel is the kernel using the same Python runtime as this process. This will put its informatino in the user kernels directory. """ - return {'argv':[sys.executable, '-c', - 'from IPython.kernel.zmq.kernelapp import main; main()', - '-f', '{connection_file}'], + return {'argv':make_ipkernel_cmd( + 'from IPython.kernel.zmq.kernelapp import main; main()'), 'display_name': 'IPython (Python %d)' % (3 if PY3 else 2), 'language': 'python', 'codemirror_mode': {'name': 'ipython', @@ -219,4 +219,4 @@ install_kernel_spec.__doc__ = KernelSpecManager.install_kernel_spec.__doc__ def install_native_kernel_spec(self, system=False): return KernelSpecManager().install_native_kernel_spec(system=system) -install_native_kernel_spec.__doc__ = KernelSpecManager.install_native_kernel_spec.__doc__ \ No newline at end of file +install_native_kernel_spec.__doc__ = KernelSpecManager.install_native_kernel_spec.__doc__ diff --git a/IPython/kernel/launcher.py b/IPython/kernel/launcher.py index dc95c04..0c9c8ea 100644 --- a/IPython/kernel/launcher.py +++ b/IPython/kernel/launcher.py @@ -97,14 +97,11 @@ def make_ipkernel_cmd(code, executable=None, extra_arguments=[], **kw): A Popen command list """ - - # Build the kernel launch command. if executable is None: executable = sys.executable arguments = [ executable, '-c', code, '-f', '{connection_file}' ] arguments.extend(extra_arguments) - # Spawn a kernel. if sys.platform == 'win32': # If the kernel is running on pythonw and stdout/stderr are not been diff --git a/IPython/kernel/manager.py b/IPython/kernel/manager.py index 318254b..9dcef8c 100644 --- a/IPython/kernel/manager.py +++ b/IPython/kernel/manager.py @@ -159,18 +159,13 @@ class KernelManager(ConnectionFileMixin): # Kernel management #-------------------------------------------------------------------------- - def format_kernel_cmd(self, **kw): + def format_kernel_cmd(self, extra_arguments=None): """replace templated args (e.g. {connection_file})""" + extra_arguments = extra_arguments or [] if self.kernel_cmd: - cmd = self.kernel_cmd - elif self.kernel_name == kernelspec.NATIVE_KERNEL_NAME: - # The native kernel gets special handling - cmd = make_ipkernel_cmd( - 'from IPython.kernel.zmq.kernelapp import main; main()', - **kw - ) + cmd = self.kernel_cmd + extra_arguments else: - cmd = self.kernel_spec.argv + cmd = self.kernel_spec.argv + extra_arguments ns = dict(connection_file=self.connection_file) ns.update(self._launch_args) @@ -227,7 +222,8 @@ class KernelManager(ConnectionFileMixin): # save kwargs for use in restart self._launch_args = kw.copy() # build the Popen cmd - kernel_cmd = self.format_kernel_cmd(**kw) + extra_arguments = kw.pop('extra_arguments', []) + kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments) if self.kernel_cmd: # If kernel_cmd has been set manually, don't refer to a kernel spec env = os.environ diff --git a/docs/source/whatsnew/pr/incompat-kernelmanager-start-args b/docs/source/whatsnew/pr/incompat-kernelmanager-start-args new file mode 100644 index 0000000..46af03e --- /dev/null +++ b/docs/source/whatsnew/pr/incompat-kernelmanager-start-args @@ -0,0 +1,2 @@ +- :meth:`~.KernelManager.start_kernel` and :meth:`~.KernelManager.format_kernel_cmd` + no longer accept a ``executable`` parameter. Use the kernelspec machinery instead.