diff --git a/IPython/html/static/notebook/js/tooltip.js b/IPython/html/static/notebook/js/tooltip.js index 63da7f3..f9d9b6a 100644 --- a/IPython/html/static/notebook/js/tooltip.js +++ b/IPython/html/static/notebook/js/tooltip.js @@ -218,7 +218,7 @@ var IPython = (function (IPython) { Tooltip.prototype._request_tooltip = function (cell, text, cursor_pos) { var callbacks = $.proxy(this._show, this); - var msg_id = cell.kernel.object_info(text, cursor_pos, callbacks); + var msg_id = cell.kernel.inspect(text, cursor_pos, callbacks); }; // make an imediate completion request diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index 75c026e..3985c5a 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -246,7 +246,7 @@ var IPython = (function (IPython) { * Get kernel info * * @param callback {function} - * @method object_info + * @method kernel_info * * When calling this method, pass a callback function that expects one argument. * The callback will be passed the complete `kernel_info_reply` message documented @@ -266,13 +266,13 @@ var IPython = (function (IPython) { * @param code {string} * @param cursor_pos {integer} * @param callback {function} - * @method object_info + * @method inspect * * When calling this method, pass a callback function that expects one argument. - * The callback will be passed the complete `object_info_reply` message documented + * The callback will be passed the complete `inspect_reply` message documented * [here](http://ipython.org/ipython-doc/dev/development/messaging.html#object-information) */ - Kernel.prototype.object_info = function (code, cursor_pos, callback) { + Kernel.prototype.inspect = function (code, cursor_pos, callback) { var callbacks; if (callback) { callbacks = { shell : { reply : callback } }; @@ -283,7 +283,7 @@ var IPython = (function (IPython) { cursor_pos : cursor_pos, detail_level : 0, }; - return this.send_shell_message("object_info_request", content, callbacks); + return this.send_shell_message("inspect_request", content, callbacks); }; /** diff --git a/IPython/kernel/channels.py b/IPython/kernel/channels.py index a0da872..73511f1 100644 --- a/IPython/kernel/channels.py +++ b/IPython/kernel/channels.py @@ -186,7 +186,7 @@ class ShellChannel(ZMQSocketChannel): proxy_methods = [ 'execute', 'complete', - 'object_info', + 'inspect', 'history', 'kernel_info', 'shutdown', @@ -290,7 +290,7 @@ class ShellChannel(ZMQSocketChannel): self._queue_send(msg) return msg['header']['msg_id'] - def object_info(self, code, cursor_pos=0, detail_level=0): + def inspect(self, code, cursor_pos=0, detail_level=0): """Get metadata information about an object in the kernel's namespace. It is up to the kernel to determine the appropriate object to inspect. @@ -312,7 +312,7 @@ class ShellChannel(ZMQSocketChannel): content = dict(code=code, cursor_pos=cursor_pos, detail_level=detail_level, ) - msg = self.session.msg('object_info_request', content) + msg = self.session.msg('inspect_request', content) self._queue_send(msg) return msg['header']['msg_id'] diff --git a/IPython/kernel/channelsabc.py b/IPython/kernel/channelsabc.py index 12aadd6..dadf612 100644 --- a/IPython/kernel/channelsabc.py +++ b/IPython/kernel/channelsabc.py @@ -46,7 +46,7 @@ class ShellChannelABC(ChannelABC): pass @abc.abstractmethod - def object_info(self, oname, detail_level=0): + def inspect(self, oname, detail_level=0): pass @abc.abstractmethod diff --git a/IPython/kernel/inprocess/channels.py b/IPython/kernel/inprocess/channels.py index 15106d0..8a7459b 100644 --- a/IPython/kernel/inprocess/channels.py +++ b/IPython/kernel/inprocess/channels.py @@ -73,7 +73,7 @@ class InProcessShellChannel(InProcessChannel): proxy_methods = [ 'execute', 'complete', - 'object_info', + 'inspect', 'history', 'shutdown', 'kernel_info', @@ -100,11 +100,11 @@ class InProcessShellChannel(InProcessChannel): self._dispatch_to_kernel(msg) return msg['header']['msg_id'] - def object_info(self, code, cursor_pos=0, detail_level=0): + def inspect(self, code, cursor_pos=0, detail_level=0): content = dict(code=code, cursor_pos=cursor_pos, detail_level=detail_level, ) - msg = self.client.session.msg('object_info_request', content) + msg = self.client.session.msg('inspect_request', content) self._dispatch_to_kernel(msg) return msg['header']['msg_id'] diff --git a/IPython/kernel/inprocess/tests/test_kernelmanager.py b/IPython/kernel/inprocess/tests/test_kernelmanager.py index 4614bf3..629dd37 100644 --- a/IPython/kernel/inprocess/tests/test_kernelmanager.py +++ b/IPython/kernel/inprocess/tests/test_kernelmanager.py @@ -68,7 +68,7 @@ class InProcessKernelManagerTestCase(unittest.TestCase): self.assertEqual(sorted(msg['content']['matches']), ['my_bar', 'my_baz']) - def test_object_info(self): + def test_inspect(self): """ Does requesting object information from an in-process kernel work? """ km = InProcessKernelManager() @@ -76,9 +76,9 @@ class InProcessKernelManagerTestCase(unittest.TestCase): kc = BlockingInProcessKernelClient(kernel=km.kernel) kc.start_channels() km.kernel.shell.user_ns['foo'] = 1 - kc.object_info('foo') + kc.inspect('foo') msg = kc.get_shell_msg() - self.assertEqual(msg['header']['msg_type'], 'object_info_reply') + self.assertEqual(msg['header']['msg_type'], 'inspect_reply') content = msg['content'] assert content['found'] self.assertEqual(content['name'], 'foo') diff --git a/IPython/kernel/tests/test_message_spec.py b/IPython/kernel/tests/test_message_spec.py index f67f2f6..36a0857 100644 --- a/IPython/kernel/tests/test_message_spec.py +++ b/IPython/kernel/tests/test_message_spec.py @@ -120,7 +120,7 @@ class ExecuteReplyError(Reference): traceback = List(Unicode) -class OInfoReply(MimeBundle): +class InspectReply(MimeBundle): name = Unicode() found = Bool() @@ -174,7 +174,7 @@ class ExecuteResult(MimeBundle): references = { 'execute_reply' : ExecuteReply(), - 'object_info_reply' : OInfoReply(), + 'inspect_reply' : InspectReply(), 'status' : Status(), 'complete_reply' : CompleteReply(), 'kernel_info_reply': KernelInfoReply(), @@ -297,9 +297,9 @@ def test_user_expressions_fail(): def test_oinfo(): flush_channels() - msg_id = KC.object_info('a') + msg_id = KC.inspect('a') reply = KC.get_shell_msg(timeout=TIMEOUT) - validate_message(reply, 'object_info_reply', msg_id) + validate_message(reply, 'inspect_reply', msg_id) def test_oinfo_found(): @@ -307,9 +307,9 @@ def test_oinfo_found(): msg_id, reply = execute(code='a=5') - msg_id = KC.object_info('a') + msg_id = KC.inspect('a') reply = KC.get_shell_msg(timeout=TIMEOUT) - validate_message(reply, 'object_info_reply', msg_id) + validate_message(reply, 'inspect_reply', msg_id) content = reply['content'] assert content['found'] nt.assert_equal(content['name'], 'a') @@ -323,9 +323,9 @@ def test_oinfo_detail(): msg_id, reply = execute(code='ip=get_ipython()') - msg_id = KC.object_info('ip.object_inspect', cursor_pos=10, detail_level=1) + msg_id = KC.inspect('ip.object_inspect', cursor_pos=10, detail_level=1) reply = KC.get_shell_msg(timeout=TIMEOUT) - validate_message(reply, 'object_info_reply', msg_id) + validate_message(reply, 'inspect_reply', msg_id) content = reply['content'] assert content['found'] nt.assert_equal(content['name'], 'ip.object_inspect') @@ -337,9 +337,9 @@ def test_oinfo_detail(): def test_oinfo_not_found(): flush_channels() - msg_id = KC.object_info('dne') + msg_id = KC.inspect('dne') reply = KC.get_shell_msg(timeout=TIMEOUT) - validate_message(reply, 'object_info_reply', msg_id) + validate_message(reply, 'inspect_reply', msg_id) content = reply['content'] nt.assert_false(content['found']) diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py index 45a88d7..27a3557 100755 --- a/IPython/kernel/zmq/ipkernel.py +++ b/IPython/kernel/zmq/ipkernel.py @@ -159,7 +159,7 @@ class Kernel(Configurable): # Build dict of handlers for message types msg_types = [ 'execute_request', 'complete_request', - 'object_info_request', 'history_request', + 'inspect_request', 'history_request', 'kernel_info_request', 'connect_request', 'shutdown_request', 'apply_request', @@ -503,7 +503,7 @@ class Kernel(Configurable): matches, parent, ident) self.log.debug("%s", completion_msg) - def object_info_request(self, stream, ident, parent): + def inspect_request(self, stream, ident, parent): content = parent['content'] name = token_at_cursor(content['code'], content['cursor_pos']) @@ -522,7 +522,7 @@ class Kernel(Configurable): reply_content['data']['text/plain'] = info_text # Before we send this object over, we scrub it for JSON usage reply_content = json_clean(reply_content) - msg = self.session.send(stream, 'object_info_reply', + msg = self.session.send(stream, 'inspect_reply', reply_content, parent, ident) self.log.debug("%s", msg) diff --git a/IPython/kernel/zmq/tests/test_embed_kernel.py b/IPython/kernel/zmq/tests/test_embed_kernel.py index fbdb02d..45f543f 100644 --- a/IPython/kernel/zmq/tests/test_embed_kernel.py +++ b/IPython/kernel/zmq/tests/test_embed_kernel.py @@ -113,7 +113,7 @@ def test_embed_kernel_basic(): with setup_kernel(cmd) as client: # oinfo a (int) - msg_id = client.object_info('a') + msg_id = client.inspect('a') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] nt.assert_true(content['found']) @@ -124,7 +124,7 @@ def test_embed_kernel_basic(): nt.assert_equal(content['status'], u'ok') # oinfo c (should be 10) - msg_id = client.object_info('c') + msg_id = client.inspect('c') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] nt.assert_true(content['found']) @@ -145,7 +145,7 @@ def test_embed_kernel_namespace(): with setup_kernel(cmd) as client: # oinfo a (int) - msg_id = client.object_info('a') + msg_id = client.inspect('a') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] nt.assert_true(content['found']) @@ -153,7 +153,7 @@ def test_embed_kernel_namespace(): nt.assert_in(u'5', text) # oinfo b (str) - msg_id = client.object_info('b') + msg_id = client.inspect('b') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] nt.assert_true(content['found']) @@ -161,7 +161,7 @@ def test_embed_kernel_namespace(): nt.assert_in(u'hi there', text) # oinfo c (undefined) - msg_id = client.object_info('c') + msg_id = client.inspect('c') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] nt.assert_false(content['found']) @@ -183,7 +183,7 @@ def test_embed_kernel_reentrant(): with setup_kernel(cmd) as client: for i in range(5): - msg_id = client.object_info('count') + msg_id = client.inspect('count') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] nt.assert_true(content['found']) diff --git a/IPython/kernel/zmq/tests/test_start_kernel.py b/IPython/kernel/zmq/tests/test_start_kernel.py index 0113255..3ac53dd 100644 --- a/IPython/kernel/zmq/tests/test_start_kernel.py +++ b/IPython/kernel/zmq/tests/test_start_kernel.py @@ -10,7 +10,7 @@ def test_ipython_start_kernel_userns(): 'start_kernel(user_ns=ns)') with setup_kernel(cmd) as client: - msg_id = client.object_info('tre') + msg_id = client.inspect('tre') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] assert content['found'] @@ -22,7 +22,7 @@ def test_ipython_start_kernel_userns(): msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] nt.assert_equal(content['status'], u'ok') - msg_id = client.object_info('usermod') + msg_id = client.inspect('usermod') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] assert content['found'] @@ -40,7 +40,7 @@ def test_ipython_start_kernel_no_userns(): msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] nt.assert_equal(content['status'], u'ok') - msg_id = client.object_info('usermod') + msg_id = client.inspect('usermod') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] assert content['found'] diff --git a/IPython/qt/console/call_tip_widget.py b/IPython/qt/console/call_tip_widget.py index 4cea749..378a138 100644 --- a/IPython/qt/console/call_tip_widget.py +++ b/IPython/qt/console/call_tip_widget.py @@ -1,5 +1,6 @@ # Standard library imports import re +import textwrap from unicodedata import category # System library imports @@ -122,21 +123,15 @@ class CallTipWidget(QtGui.QLabel): # 'CallTipWidget' interface #-------------------------------------------------------------------------- - def show_call_info(self, call_line=None, doc=None, maxlines=20): - """ Attempts to show the specified call line and docstring at the - current cursor location. The docstring is possibly truncated for - length. - """ - if doc: - match = re.match("(?:[^\n]*\n){%i}" % maxlines, doc) - if match: - doc = doc[:match.end()] + '\n[Documentation continues...]' - else: - doc = '' + def show_inspect_data(self, content, maxlines=20): + """Show inspection data as a tooltip""" + data = content.get('data', {}) + text = data.get('text/plain', '') + match = re.match("(?:[^\n]*\n){%i}" % maxlines, text) + if match: + text = text[:match.end()] + '\n[Documentation continues...]' - if call_line: - doc = '\n\n'.join([call_line, doc]) - return self.show_tip(self._format_tooltip(doc)) + return self.show_tip(self._format_tooltip(text)) def show_tip(self, tip): """ Attempts to show the specified tip at the current cursor location. @@ -247,8 +242,8 @@ class CallTipWidget(QtGui.QLabel): QtGui.qApp.topLevelAt(QtGui.QCursor.pos()) != self): self._hide_timer.start(300, self) - def _format_tooltip(self,doc): - import textwrap + def _format_tooltip(self, doc): + doc = re.sub(r'\033\[(\d|;)+?m', '', doc) # make sure a long argument list does not make # the first row overflow the width of the actual tip body diff --git a/IPython/qt/console/frontend_widget.py b/IPython/qt/console/frontend_widget.py index 3d7a816..00de669 100644 --- a/IPython/qt/console/frontend_widget.py +++ b/IPython/qt/console/frontend_widget.py @@ -505,9 +505,8 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): self._kernel_restarted_message(died=died) self.reset() - def _handle_object_info_reply(self, rep): - """ Handle replies for call tips. - """ + def _handle_inspect_reply(self, rep): + """Handle replies for call tips.""" self.log.debug("oinfo: %s", rep.get('content', '')) cursor = self._get_cursor() info = self._request_info.get('call_tip') @@ -518,16 +517,8 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): # syntax-highlight it ourselves for nicer formatting in the # calltip. content = rep['content'] - # if this is from pykernel, 'docstring' will be the only key - if content.get('ismagic', False): - # Don't generate a call-tip for magics. Ideally, we should - # generate a tooltip, but not on ( like we do for actual - # callables. - call_info, doc = None, None - else: - call_info, doc = call_tip(content, format_call=True) - if call_info or doc: - self._call_tip_widget.show_call_info(call_info, doc) + if content.get('status') == 'ok': + self._call_tip_widget.show_inspect_data(content) def _handle_execute_result(self, msg): """ Handle display hook output. @@ -734,7 +725,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): cursor_pos = self._get_input_buffer_cursor_pos() code = self.input_buffer # Send the metadata request to the kernel - msg_id = self.kernel_client.object_info(code, cursor_pos) + msg_id = self.kernel_client.inspect(code, cursor_pos) pos = self._get_cursor().position() self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos) return True diff --git a/IPython/qt/kernel_mixins.py b/IPython/qt/kernel_mixins.py index 9e35c2b..667aa0e 100644 --- a/IPython/qt/kernel_mixins.py +++ b/IPython/qt/kernel_mixins.py @@ -57,7 +57,7 @@ class QtShellChannelMixin(ChannelQObject): # Emitted when a reply has been received for the corresponding request type. execute_reply = QtCore.Signal(object) complete_reply = QtCore.Signal(object) - object_info_reply = QtCore.Signal(object) + inspect_reply = QtCore.Signal(object) history_reply = QtCore.Signal(object) #---------------------------------------------------------------------------