From 26aac1d1c2270f4165feb5bc88c97496a5948a0f Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Sun, 25 Nov 2012 22:12:50 +0100 Subject: [PATCH 1/5] add ability to bind to a ruby kernel this (for now) need the iruby patch of my branch, and to modify a hardcoded path in IPython/zmq/rubykernel.py Launch with ipython notebook --MappingKernelManager.kernel_manager_class='IPython.zmq.rubykernel.RubyKernelManager' need zmq, uuid and hmac gem, and ruby 1.9.3 --- IPython/frontend/html/notebook/kernelmanager.py | 1 + IPython/zmq/rubykernel.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 IPython/zmq/rubykernel.py diff --git a/IPython/frontend/html/notebook/kernelmanager.py b/IPython/frontend/html/notebook/kernelmanager.py index 28f6c4d8135..ac2887d5977 100644 --- a/IPython/frontend/html/notebook/kernelmanager.py +++ b/IPython/frontend/html/notebook/kernelmanager.py @@ -28,6 +28,7 @@ from IPython.config.configurable import LoggingConfigurable from IPython.utils.importstring import import_item +from IPython.zmq.rubykernel import RubyKernelManager from IPython.utils.traitlets import ( Instance, Dict, List, Unicode, Float, Integer, Any, DottedObjectName, ) diff --git a/IPython/zmq/rubykernel.py b/IPython/zmq/rubykernel.py new file mode 100644 index 00000000000..d633df68447 --- /dev/null +++ b/IPython/zmq/rubykernel.py @@ -0,0 +1,16 @@ +from subprocess import Popen + +from IPython.zmq.kernelmanager import KernelManager + +def launch_ruby_kernel(fname='cf.json', **kw): + cmd = ['iruby_ruby', '~/iruby/lib/kernel.rb', fname] + cmd = ['/usr/local/Cellar/ruby/1.9.3-p286/bin/ruby', + '/Users/matthiasbussonnier/iruby/lib/kernel.rb', + fname] + #~/.ipython/profile_default/security/kernel-10234.json + return Popen(cmd) + +class RubyKernelManager(KernelManager): + def start_kernel(self, **kw): + kw['launcher'] = launch_ruby_kernel + return KernelManager.start_kernel(self, **kw) From 3ddce3a94aa06178e39afbd8e23cd2a07ccdebfe Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Tue, 4 Dec 2012 08:23:55 +0100 Subject: [PATCH 2/5] subprocess kernel manager --- .../frontend/html/notebook/kernelmanager.py | 1 - IPython/zmq/rubykernel.py | 16 ------------ IPython/zmq/subprocesskernel.py | 26 +++++++++++++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) delete mode 100644 IPython/zmq/rubykernel.py create mode 100644 IPython/zmq/subprocesskernel.py diff --git a/IPython/frontend/html/notebook/kernelmanager.py b/IPython/frontend/html/notebook/kernelmanager.py index ac2887d5977..28f6c4d8135 100644 --- a/IPython/frontend/html/notebook/kernelmanager.py +++ b/IPython/frontend/html/notebook/kernelmanager.py @@ -28,7 +28,6 @@ from IPython.config.configurable import LoggingConfigurable from IPython.utils.importstring import import_item -from IPython.zmq.rubykernel import RubyKernelManager from IPython.utils.traitlets import ( Instance, Dict, List, Unicode, Float, Integer, Any, DottedObjectName, ) diff --git a/IPython/zmq/rubykernel.py b/IPython/zmq/rubykernel.py deleted file mode 100644 index d633df68447..00000000000 --- a/IPython/zmq/rubykernel.py +++ /dev/null @@ -1,16 +0,0 @@ -from subprocess import Popen - -from IPython.zmq.kernelmanager import KernelManager - -def launch_ruby_kernel(fname='cf.json', **kw): - cmd = ['iruby_ruby', '~/iruby/lib/kernel.rb', fname] - cmd = ['/usr/local/Cellar/ruby/1.9.3-p286/bin/ruby', - '/Users/matthiasbussonnier/iruby/lib/kernel.rb', - fname] - #~/.ipython/profile_default/security/kernel-10234.json - return Popen(cmd) - -class RubyKernelManager(KernelManager): - def start_kernel(self, **kw): - kw['launcher'] = launch_ruby_kernel - return KernelManager.start_kernel(self, **kw) diff --git a/IPython/zmq/subprocesskernel.py b/IPython/zmq/subprocesskernel.py new file mode 100644 index 00000000000..a7c71776191 --- /dev/null +++ b/IPython/zmq/subprocesskernel.py @@ -0,0 +1,26 @@ +from subprocess import Popen + +from IPython.zmq.kernelmanager import KernelManager +from IPython.utils.traitlets import Unicode + + +class SubprocessKernelManager(KernelManager): + + kernel_launch_command = Unicode( + 'echo "this is not configurated"', + config=True, + help="""the command to launch a foreing language kernel, use %(cfile) to have + the full path of the connexion file. + """ + ) + + def start_kernel(self, **kw): + kw['launcher'] = self.launch_ruby_kernel + return KernelManager.start_kernel(self, **kw) + + def launch_ruby_kernel(self, fname='cf.json', **kw): + cmd = ['/usr/local/Cellar/ruby/1.9.3-p286/bin/ruby', + '/Users/matthiasbussonnier/iruby/lib/kernel.rb', + fname] + #~/.ipython/profile_default/security/kernel-10234.json + return Popen(cmd) From bb0b397ad5fd7cc49fe39e28bc52a75005eac8cb Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Tue, 4 Dec 2012 10:09:03 +0100 Subject: [PATCH 3/5] working generic subprocess --- IPython/zmq/subprocesskernel.py | 39 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/IPython/zmq/subprocesskernel.py b/IPython/zmq/subprocesskernel.py index a7c71776191..d1d4196b588 100644 --- a/IPython/zmq/subprocesskernel.py +++ b/IPython/zmq/subprocesskernel.py @@ -1,26 +1,43 @@ +#----------------------------------------------------------------------------- +# Copyright (C) 2012 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + + from subprocess import Popen +from os.path import expanduser as expanduser from IPython.zmq.kernelmanager import KernelManager -from IPython.utils.traitlets import Unicode +from IPython.utils.traitlets import List +from IPython.config.configurable import Configurable -class SubprocessKernelManager(KernelManager): +class SubprocessKernelManager(KernelManager, Configurable): - kernel_launch_command = Unicode( - 'echo "this is not configurated"', + kernel_launch_program = List( + [], config=True, - help="""the command to launch a foreing language kernel, use %(cfile) to have + help="""the command to launch a foreing language kernel, use '{connexion_file_name}' to have the full path of the connexion file. """ ) def start_kernel(self, **kw): - kw['launcher'] = self.launch_ruby_kernel + kw['launcher'] = self.launch_subprocess_kernel return KernelManager.start_kernel(self, **kw) - def launch_ruby_kernel(self, fname='cf.json', **kw): - cmd = ['/usr/local/Cellar/ruby/1.9.3-p286/bin/ruby', - '/Users/matthiasbussonnier/iruby/lib/kernel.rb', - fname] - #~/.ipython/profile_default/security/kernel-10234.json + def launch_subprocess_kernel(self, fname='cf.json', **kw): + if not self.kernel_launch_program : + raise ValueError("""kernel_launch program should be defined + in config with the following form : + + c.SubprocessKernelManager.kernel_launch_program=['interpreter','program','{connexion_file_name}'] + """) + cmd = [ expanduser(_.format(connexion_file_name=fname)) for _ in self.kernel_launch_program] return Popen(cmd) From 6c544dbbf609e638b942ce10c7eb0baab47a02bc Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Tue, 4 Dec 2012 11:27:46 +0100 Subject: [PATCH 4/5] remove useless "as expanduser" --- IPython/zmq/subprocesskernel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/zmq/subprocesskernel.py b/IPython/zmq/subprocesskernel.py index d1d4196b588..6993fccdc7d 100644 --- a/IPython/zmq/subprocesskernel.py +++ b/IPython/zmq/subprocesskernel.py @@ -11,7 +11,7 @@ from subprocess import Popen -from os.path import expanduser as expanduser +from os.path import expanduser from IPython.zmq.kernelmanager import KernelManager from IPython.utils.traitlets import List From 5e10e8d755a571f6960e39970bc2a0db06eee5b0 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Tue, 4 Dec 2012 13:00:23 +0100 Subject: [PATCH 5/5] fix english --- IPython/zmq/subprocesskernel.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/IPython/zmq/subprocesskernel.py b/IPython/zmq/subprocesskernel.py index 6993fccdc7d..0556bf10500 100644 --- a/IPython/zmq/subprocesskernel.py +++ b/IPython/zmq/subprocesskernel.py @@ -23,8 +23,8 @@ class SubprocessKernelManager(KernelManager, Configurable): kernel_launch_program = List( [], config=True, - help="""the command to launch a foreing language kernel, use '{connexion_file_name}' to have - the full path of the connexion file. + help="""the command to launch a foreign language kernel, use '{connection_file_name}' to have + the full path of the connection file. """ ) @@ -37,7 +37,7 @@ def launch_subprocess_kernel(self, fname='cf.json', **kw): raise ValueError("""kernel_launch program should be defined in config with the following form : - c.SubprocessKernelManager.kernel_launch_program=['interpreter','program','{connexion_file_name}'] + c.SubprocessKernelManager.kernel_launch_program=['interpreter','program','{connection_file_name}'] """) - cmd = [ expanduser(_.format(connexion_file_name=fname)) for _ in self.kernel_launch_program] + cmd = [ expanduser(_.format(connection_file_name=fname)) for _ in self.kernel_launch_program] return Popen(cmd)