From 6f45747ff924befb95273d7930a351c6a00093b6 2014-06-06 00:01:20 From: Thomas Kluyver Date: 2014-06-06 00:01:20 Subject: [PATCH] Stub out kernel methods to allow overriding a subset of them. --- diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py index 31bad97..c3e3d3d 100644 --- a/IPython/kernel/zmq/ipkernel.py +++ b/IPython/kernel/zmq/ipkernel.py @@ -68,6 +68,10 @@ class Kernel(KernelBase): def banner(self): return self.shell.banner + def start(self): + self.shell.exit_now = False + super(Kernel, self).start() + def set_parent(self, ident, parent): """Overridden from parent to tell the display hook and output streams about the parent message. diff --git a/IPython/kernel/zmq/kernelbase.py b/IPython/kernel/zmq/kernelbase.py index 5a42774..80e5a3e 100755 --- a/IPython/kernel/zmq/kernelbase.py +++ b/IPython/kernel/zmq/kernelbase.py @@ -225,7 +225,6 @@ class KernelBase(Configurable): def start(self): """register dispatchers for streams""" - self.shell.exit_now = False if self.control_stream: self.control_stream.on_recv(self.dispatch_control, copy=False) @@ -374,6 +373,12 @@ class KernelBase(Configurable): self._publish_status(u'idle', parent) + def do_execute(self, code, silent, store_history=True, + user_experssions=None, allow_stdin=False): + """Execute user code. Must be overridden by subclasses. + """ + raise NotImplementedError + def complete_request(self, stream, ident, parent): content = parent['content'] code = content['code'] @@ -385,6 +390,15 @@ class KernelBase(Configurable): matches, parent, ident) self.log.debug("%s", completion_msg) + def do_complete(self, code, cursor_pos): + """Override in subclasses to find completions. + """ + return {'matches' : [], + 'cursor_end' : cursor_pos, + 'cursor_start' : cursor_pos, + 'metadata' : {}, + 'status' : 'ok'} + def inspect_request(self, stream, ident, parent): content = parent['content'] @@ -396,6 +410,11 @@ class KernelBase(Configurable): reply_content, parent, ident) self.log.debug("%s", msg) + def do_inspect(self, code, cursor_pos, detail_level=0): + """Override in subclasses to allow introspection. + """ + return {'status': 'ok', 'data':{}, 'metadata':{}, 'found':False} + def history_request(self, stream, ident, parent): # We need to pull these out, as passing **kwargs doesn't work with # unicode keys before Python 2.6.5. @@ -416,6 +435,12 @@ class KernelBase(Configurable): reply_content, parent, ident) self.log.debug("%s", msg) + def do_history(self, hist_access_type, output, raw, session=None, start=None, + stop=None, n=None, pattern=None, unique=False): + """Override in subclasses to access history. + """ + return {'history': []} + def connect_request(self, stream, ident, parent): if self._recorded_ports is not None: content = self._recorded_ports.copy() @@ -454,6 +479,12 @@ class KernelBase(Configurable): loop = ioloop.IOLoop.instance() loop.add_timeout(time.time()+0.1, loop.stop) + def do_shutdown(self, restart): + """Override in subclasses to do things when the frontend shuts down the + kernel. + """ + return {'status': 'ok', 'restart': restart} + #--------------------------------------------------------------------------- # Engine methods #--------------------------------------------------------------------------- @@ -488,6 +519,11 @@ class KernelBase(Configurable): self._publish_status(u'idle', parent) + def do_apply(self, content, bufs, msg_id, reply_metadata): + """Override in subclasses to support the IPython parallel framework. + """ + raise NotImplementedError + #--------------------------------------------------------------------------- # Control messages #--------------------------------------------------------------------------- @@ -513,6 +549,13 @@ class KernelBase(Configurable): self.session.send(stream, 'clear_reply', ident=idents, parent=parent, content = content) + def do_clear(self): + """Override in subclasses to clear the namespace + + This is only required for IPython.parallel. + """ + raise NotImplementedError + #--------------------------------------------------------------------------- # Protected interface #---------------------------------------------------------------------------