##// END OF EJS Templates
s/object_info_request/inspect_request
MinRK -
Show More
@@ -218,7 +218,7 b' var IPython = (function (IPython) {'
218
218
219 Tooltip.prototype._request_tooltip = function (cell, text, cursor_pos) {
219 Tooltip.prototype._request_tooltip = function (cell, text, cursor_pos) {
220 var callbacks = $.proxy(this._show, this);
220 var callbacks = $.proxy(this._show, this);
221 var msg_id = cell.kernel.object_info(text, cursor_pos, callbacks);
221 var msg_id = cell.kernel.inspect(text, cursor_pos, callbacks);
222 };
222 };
223
223
224 // make an imediate completion request
224 // make an imediate completion request
@@ -246,7 +246,7 b' var IPython = (function (IPython) {'
246 * Get kernel info
246 * Get kernel info
247 *
247 *
248 * @param callback {function}
248 * @param callback {function}
249 * @method object_info
249 * @method kernel_info
250 *
250 *
251 * When calling this method, pass a callback function that expects one argument.
251 * When calling this method, pass a callback function that expects one argument.
252 * The callback will be passed the complete `kernel_info_reply` message documented
252 * The callback will be passed the complete `kernel_info_reply` message documented
@@ -266,13 +266,13 b' var IPython = (function (IPython) {'
266 * @param code {string}
266 * @param code {string}
267 * @param cursor_pos {integer}
267 * @param cursor_pos {integer}
268 * @param callback {function}
268 * @param callback {function}
269 * @method object_info
269 * @method inspect
270 *
270 *
271 * When calling this method, pass a callback function that expects one argument.
271 * When calling this method, pass a callback function that expects one argument.
272 * The callback will be passed the complete `object_info_reply` message documented
272 * The callback will be passed the complete `inspect_reply` message documented
273 * [here](http://ipython.org/ipython-doc/dev/development/messaging.html#object-information)
273 * [here](http://ipython.org/ipython-doc/dev/development/messaging.html#object-information)
274 */
274 */
275 Kernel.prototype.object_info = function (code, cursor_pos, callback) {
275 Kernel.prototype.inspect = function (code, cursor_pos, callback) {
276 var callbacks;
276 var callbacks;
277 if (callback) {
277 if (callback) {
278 callbacks = { shell : { reply : callback } };
278 callbacks = { shell : { reply : callback } };
@@ -283,7 +283,7 b' var IPython = (function (IPython) {'
283 cursor_pos : cursor_pos,
283 cursor_pos : cursor_pos,
284 detail_level : 0,
284 detail_level : 0,
285 };
285 };
286 return this.send_shell_message("object_info_request", content, callbacks);
286 return this.send_shell_message("inspect_request", content, callbacks);
287 };
287 };
288
288
289 /**
289 /**
@@ -186,7 +186,7 b' class ShellChannel(ZMQSocketChannel):'
186 proxy_methods = [
186 proxy_methods = [
187 'execute',
187 'execute',
188 'complete',
188 'complete',
189 'object_info',
189 'inspect',
190 'history',
190 'history',
191 'kernel_info',
191 'kernel_info',
192 'shutdown',
192 'shutdown',
@@ -290,7 +290,7 b' class ShellChannel(ZMQSocketChannel):'
290 self._queue_send(msg)
290 self._queue_send(msg)
291 return msg['header']['msg_id']
291 return msg['header']['msg_id']
292
292
293 def object_info(self, code, cursor_pos=0, detail_level=0):
293 def inspect(self, code, cursor_pos=0, detail_level=0):
294 """Get metadata information about an object in the kernel's namespace.
294 """Get metadata information about an object in the kernel's namespace.
295
295
296 It is up to the kernel to determine the appropriate object to inspect.
296 It is up to the kernel to determine the appropriate object to inspect.
@@ -312,7 +312,7 b' class ShellChannel(ZMQSocketChannel):'
312 content = dict(code=code, cursor_pos=cursor_pos,
312 content = dict(code=code, cursor_pos=cursor_pos,
313 detail_level=detail_level,
313 detail_level=detail_level,
314 )
314 )
315 msg = self.session.msg('object_info_request', content)
315 msg = self.session.msg('inspect_request', content)
316 self._queue_send(msg)
316 self._queue_send(msg)
317 return msg['header']['msg_id']
317 return msg['header']['msg_id']
318
318
@@ -46,7 +46,7 b' class ShellChannelABC(ChannelABC):'
46 pass
46 pass
47
47
48 @abc.abstractmethod
48 @abc.abstractmethod
49 def object_info(self, oname, detail_level=0):
49 def inspect(self, oname, detail_level=0):
50 pass
50 pass
51
51
52 @abc.abstractmethod
52 @abc.abstractmethod
@@ -73,7 +73,7 b' class InProcessShellChannel(InProcessChannel):'
73 proxy_methods = [
73 proxy_methods = [
74 'execute',
74 'execute',
75 'complete',
75 'complete',
76 'object_info',
76 'inspect',
77 'history',
77 'history',
78 'shutdown',
78 'shutdown',
79 'kernel_info',
79 'kernel_info',
@@ -100,11 +100,11 b' class InProcessShellChannel(InProcessChannel):'
100 self._dispatch_to_kernel(msg)
100 self._dispatch_to_kernel(msg)
101 return msg['header']['msg_id']
101 return msg['header']['msg_id']
102
102
103 def object_info(self, code, cursor_pos=0, detail_level=0):
103 def inspect(self, code, cursor_pos=0, detail_level=0):
104 content = dict(code=code, cursor_pos=cursor_pos,
104 content = dict(code=code, cursor_pos=cursor_pos,
105 detail_level=detail_level,
105 detail_level=detail_level,
106 )
106 )
107 msg = self.client.session.msg('object_info_request', content)
107 msg = self.client.session.msg('inspect_request', content)
108 self._dispatch_to_kernel(msg)
108 self._dispatch_to_kernel(msg)
109 return msg['header']['msg_id']
109 return msg['header']['msg_id']
110
110
@@ -68,7 +68,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):'
68 self.assertEqual(sorted(msg['content']['matches']),
68 self.assertEqual(sorted(msg['content']['matches']),
69 ['my_bar', 'my_baz'])
69 ['my_bar', 'my_baz'])
70
70
71 def test_object_info(self):
71 def test_inspect(self):
72 """ Does requesting object information from an in-process kernel work?
72 """ Does requesting object information from an in-process kernel work?
73 """
73 """
74 km = InProcessKernelManager()
74 km = InProcessKernelManager()
@@ -76,9 +76,9 b' class InProcessKernelManagerTestCase(unittest.TestCase):'
76 kc = BlockingInProcessKernelClient(kernel=km.kernel)
76 kc = BlockingInProcessKernelClient(kernel=km.kernel)
77 kc.start_channels()
77 kc.start_channels()
78 km.kernel.shell.user_ns['foo'] = 1
78 km.kernel.shell.user_ns['foo'] = 1
79 kc.object_info('foo')
79 kc.inspect('foo')
80 msg = kc.get_shell_msg()
80 msg = kc.get_shell_msg()
81 self.assertEqual(msg['header']['msg_type'], 'object_info_reply')
81 self.assertEqual(msg['header']['msg_type'], 'inspect_reply')
82 content = msg['content']
82 content = msg['content']
83 assert content['found']
83 assert content['found']
84 self.assertEqual(content['name'], 'foo')
84 self.assertEqual(content['name'], 'foo')
@@ -120,7 +120,7 b' class ExecuteReplyError(Reference):'
120 traceback = List(Unicode)
120 traceback = List(Unicode)
121
121
122
122
123 class OInfoReply(MimeBundle):
123 class InspectReply(MimeBundle):
124 name = Unicode()
124 name = Unicode()
125 found = Bool()
125 found = Bool()
126
126
@@ -174,7 +174,7 b' class ExecuteResult(MimeBundle):'
174
174
175 references = {
175 references = {
176 'execute_reply' : ExecuteReply(),
176 'execute_reply' : ExecuteReply(),
177 'object_info_reply' : OInfoReply(),
177 'inspect_reply' : InspectReply(),
178 'status' : Status(),
178 'status' : Status(),
179 'complete_reply' : CompleteReply(),
179 'complete_reply' : CompleteReply(),
180 'kernel_info_reply': KernelInfoReply(),
180 'kernel_info_reply': KernelInfoReply(),
@@ -297,9 +297,9 b' def test_user_expressions_fail():'
297 def test_oinfo():
297 def test_oinfo():
298 flush_channels()
298 flush_channels()
299
299
300 msg_id = KC.object_info('a')
300 msg_id = KC.inspect('a')
301 reply = KC.get_shell_msg(timeout=TIMEOUT)
301 reply = KC.get_shell_msg(timeout=TIMEOUT)
302 validate_message(reply, 'object_info_reply', msg_id)
302 validate_message(reply, 'inspect_reply', msg_id)
303
303
304
304
305 def test_oinfo_found():
305 def test_oinfo_found():
@@ -307,9 +307,9 b' def test_oinfo_found():'
307
307
308 msg_id, reply = execute(code='a=5')
308 msg_id, reply = execute(code='a=5')
309
309
310 msg_id = KC.object_info('a')
310 msg_id = KC.inspect('a')
311 reply = KC.get_shell_msg(timeout=TIMEOUT)
311 reply = KC.get_shell_msg(timeout=TIMEOUT)
312 validate_message(reply, 'object_info_reply', msg_id)
312 validate_message(reply, 'inspect_reply', msg_id)
313 content = reply['content']
313 content = reply['content']
314 assert content['found']
314 assert content['found']
315 nt.assert_equal(content['name'], 'a')
315 nt.assert_equal(content['name'], 'a')
@@ -323,9 +323,9 b' def test_oinfo_detail():'
323
323
324 msg_id, reply = execute(code='ip=get_ipython()')
324 msg_id, reply = execute(code='ip=get_ipython()')
325
325
326 msg_id = KC.object_info('ip.object_inspect', cursor_pos=10, detail_level=1)
326 msg_id = KC.inspect('ip.object_inspect', cursor_pos=10, detail_level=1)
327 reply = KC.get_shell_msg(timeout=TIMEOUT)
327 reply = KC.get_shell_msg(timeout=TIMEOUT)
328 validate_message(reply, 'object_info_reply', msg_id)
328 validate_message(reply, 'inspect_reply', msg_id)
329 content = reply['content']
329 content = reply['content']
330 assert content['found']
330 assert content['found']
331 nt.assert_equal(content['name'], 'ip.object_inspect')
331 nt.assert_equal(content['name'], 'ip.object_inspect')
@@ -337,9 +337,9 b' def test_oinfo_detail():'
337 def test_oinfo_not_found():
337 def test_oinfo_not_found():
338 flush_channels()
338 flush_channels()
339
339
340 msg_id = KC.object_info('dne')
340 msg_id = KC.inspect('dne')
341 reply = KC.get_shell_msg(timeout=TIMEOUT)
341 reply = KC.get_shell_msg(timeout=TIMEOUT)
342 validate_message(reply, 'object_info_reply', msg_id)
342 validate_message(reply, 'inspect_reply', msg_id)
343 content = reply['content']
343 content = reply['content']
344 nt.assert_false(content['found'])
344 nt.assert_false(content['found'])
345
345
@@ -159,7 +159,7 b' class Kernel(Configurable):'
159
159
160 # Build dict of handlers for message types
160 # Build dict of handlers for message types
161 msg_types = [ 'execute_request', 'complete_request',
161 msg_types = [ 'execute_request', 'complete_request',
162 'object_info_request', 'history_request',
162 'inspect_request', 'history_request',
163 'kernel_info_request',
163 'kernel_info_request',
164 'connect_request', 'shutdown_request',
164 'connect_request', 'shutdown_request',
165 'apply_request',
165 'apply_request',
@@ -503,7 +503,7 b' class Kernel(Configurable):'
503 matches, parent, ident)
503 matches, parent, ident)
504 self.log.debug("%s", completion_msg)
504 self.log.debug("%s", completion_msg)
505
505
506 def object_info_request(self, stream, ident, parent):
506 def inspect_request(self, stream, ident, parent):
507 content = parent['content']
507 content = parent['content']
508
508
509 name = token_at_cursor(content['code'], content['cursor_pos'])
509 name = token_at_cursor(content['code'], content['cursor_pos'])
@@ -522,7 +522,7 b' class Kernel(Configurable):'
522 reply_content['data']['text/plain'] = info_text
522 reply_content['data']['text/plain'] = info_text
523 # Before we send this object over, we scrub it for JSON usage
523 # Before we send this object over, we scrub it for JSON usage
524 reply_content = json_clean(reply_content)
524 reply_content = json_clean(reply_content)
525 msg = self.session.send(stream, 'object_info_reply',
525 msg = self.session.send(stream, 'inspect_reply',
526 reply_content, parent, ident)
526 reply_content, parent, ident)
527 self.log.debug("%s", msg)
527 self.log.debug("%s", msg)
528
528
@@ -113,7 +113,7 b' def test_embed_kernel_basic():'
113
113
114 with setup_kernel(cmd) as client:
114 with setup_kernel(cmd) as client:
115 # oinfo a (int)
115 # oinfo a (int)
116 msg_id = client.object_info('a')
116 msg_id = client.inspect('a')
117 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
117 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
118 content = msg['content']
118 content = msg['content']
119 nt.assert_true(content['found'])
119 nt.assert_true(content['found'])
@@ -124,7 +124,7 b' def test_embed_kernel_basic():'
124 nt.assert_equal(content['status'], u'ok')
124 nt.assert_equal(content['status'], u'ok')
125
125
126 # oinfo c (should be 10)
126 # oinfo c (should be 10)
127 msg_id = client.object_info('c')
127 msg_id = client.inspect('c')
128 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
128 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
129 content = msg['content']
129 content = msg['content']
130 nt.assert_true(content['found'])
130 nt.assert_true(content['found'])
@@ -145,7 +145,7 b' def test_embed_kernel_namespace():'
145
145
146 with setup_kernel(cmd) as client:
146 with setup_kernel(cmd) as client:
147 # oinfo a (int)
147 # oinfo a (int)
148 msg_id = client.object_info('a')
148 msg_id = client.inspect('a')
149 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
149 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
150 content = msg['content']
150 content = msg['content']
151 nt.assert_true(content['found'])
151 nt.assert_true(content['found'])
@@ -153,7 +153,7 b' def test_embed_kernel_namespace():'
153 nt.assert_in(u'5', text)
153 nt.assert_in(u'5', text)
154
154
155 # oinfo b (str)
155 # oinfo b (str)
156 msg_id = client.object_info('b')
156 msg_id = client.inspect('b')
157 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
157 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
158 content = msg['content']
158 content = msg['content']
159 nt.assert_true(content['found'])
159 nt.assert_true(content['found'])
@@ -161,7 +161,7 b' def test_embed_kernel_namespace():'
161 nt.assert_in(u'hi there', text)
161 nt.assert_in(u'hi there', text)
162
162
163 # oinfo c (undefined)
163 # oinfo c (undefined)
164 msg_id = client.object_info('c')
164 msg_id = client.inspect('c')
165 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
165 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
166 content = msg['content']
166 content = msg['content']
167 nt.assert_false(content['found'])
167 nt.assert_false(content['found'])
@@ -183,7 +183,7 b' def test_embed_kernel_reentrant():'
183
183
184 with setup_kernel(cmd) as client:
184 with setup_kernel(cmd) as client:
185 for i in range(5):
185 for i in range(5):
186 msg_id = client.object_info('count')
186 msg_id = client.inspect('count')
187 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
187 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
188 content = msg['content']
188 content = msg['content']
189 nt.assert_true(content['found'])
189 nt.assert_true(content['found'])
@@ -10,7 +10,7 b' def test_ipython_start_kernel_userns():'
10 'start_kernel(user_ns=ns)')
10 'start_kernel(user_ns=ns)')
11
11
12 with setup_kernel(cmd) as client:
12 with setup_kernel(cmd) as client:
13 msg_id = client.object_info('tre')
13 msg_id = client.inspect('tre')
14 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
14 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
15 content = msg['content']
15 content = msg['content']
16 assert content['found']
16 assert content['found']
@@ -22,7 +22,7 b' def test_ipython_start_kernel_userns():'
22 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
22 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
23 content = msg['content']
23 content = msg['content']
24 nt.assert_equal(content['status'], u'ok')
24 nt.assert_equal(content['status'], u'ok')
25 msg_id = client.object_info('usermod')
25 msg_id = client.inspect('usermod')
26 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
26 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
27 content = msg['content']
27 content = msg['content']
28 assert content['found']
28 assert content['found']
@@ -40,7 +40,7 b' def test_ipython_start_kernel_no_userns():'
40 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
40 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
41 content = msg['content']
41 content = msg['content']
42 nt.assert_equal(content['status'], u'ok')
42 nt.assert_equal(content['status'], u'ok')
43 msg_id = client.object_info('usermod')
43 msg_id = client.inspect('usermod')
44 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
44 msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
45 content = msg['content']
45 content = msg['content']
46 assert content['found']
46 assert content['found']
@@ -1,5 +1,6 b''
1 # Standard library imports
1 # Standard library imports
2 import re
2 import re
3 import textwrap
3 from unicodedata import category
4 from unicodedata import category
4
5
5 # System library imports
6 # System library imports
@@ -122,21 +123,15 b' class CallTipWidget(QtGui.QLabel):'
122 # 'CallTipWidget' interface
123 # 'CallTipWidget' interface
123 #--------------------------------------------------------------------------
124 #--------------------------------------------------------------------------
124
125
125 def show_call_info(self, call_line=None, doc=None, maxlines=20):
126 def show_inspect_data(self, content, maxlines=20):
126 """ Attempts to show the specified call line and docstring at the
127 """Show inspection data as a tooltip"""
127 current cursor location. The docstring is possibly truncated for
128 data = content.get('data', {})
128 length.
129 text = data.get('text/plain', '')
129 """
130 match = re.match("(?:[^\n]*\n){%i}" % maxlines, text)
130 if doc:
131 match = re.match("(?:[^\n]*\n){%i}" % maxlines, doc)
132 if match:
131 if match:
133 doc = doc[:match.end()] + '\n[Documentation continues...]'
132 text = text[:match.end()] + '\n[Documentation continues...]'
134 else:
135 doc = ''
136
133
137 if call_line:
134 return self.show_tip(self._format_tooltip(text))
138 doc = '\n\n'.join([call_line, doc])
139 return self.show_tip(self._format_tooltip(doc))
140
135
141 def show_tip(self, tip):
136 def show_tip(self, tip):
142 """ Attempts to show the specified tip at the current cursor location.
137 """ Attempts to show the specified tip at the current cursor location.
@@ -248,7 +243,7 b' class CallTipWidget(QtGui.QLabel):'
248 self._hide_timer.start(300, self)
243 self._hide_timer.start(300, self)
249
244
250 def _format_tooltip(self,doc):
245 def _format_tooltip(self, doc):
251 import textwrap
246 doc = re.sub(r'\033\[(\d|;)+?m', '', doc)
252
247
253 # make sure a long argument list does not make
248 # make sure a long argument list does not make
254 # the first row overflow the width of the actual tip body
249 # the first row overflow the width of the actual tip body
@@ -505,9 +505,8 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
505 self._kernel_restarted_message(died=died)
505 self._kernel_restarted_message(died=died)
506 self.reset()
506 self.reset()
507
507
508 def _handle_object_info_reply(self, rep):
508 def _handle_inspect_reply(self, rep):
509 """ Handle replies for call tips.
509 """Handle replies for call tips."""
510 """
511 self.log.debug("oinfo: %s", rep.get('content', ''))
510 self.log.debug("oinfo: %s", rep.get('content', ''))
512 cursor = self._get_cursor()
511 cursor = self._get_cursor()
513 info = self._request_info.get('call_tip')
512 info = self._request_info.get('call_tip')
@@ -518,16 +517,8 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
518 # syntax-highlight it ourselves for nicer formatting in the
517 # syntax-highlight it ourselves for nicer formatting in the
519 # calltip.
518 # calltip.
520 content = rep['content']
519 content = rep['content']
521 # if this is from pykernel, 'docstring' will be the only key
520 if content.get('status') == 'ok':
522 if content.get('ismagic', False):
521 self._call_tip_widget.show_inspect_data(content)
523 # Don't generate a call-tip for magics. Ideally, we should
524 # generate a tooltip, but not on ( like we do for actual
525 # callables.
526 call_info, doc = None, None
527 else:
528 call_info, doc = call_tip(content, format_call=True)
529 if call_info or doc:
530 self._call_tip_widget.show_call_info(call_info, doc)
531
522
532 def _handle_execute_result(self, msg):
523 def _handle_execute_result(self, msg):
533 """ Handle display hook output.
524 """ Handle display hook output.
@@ -734,7 +725,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
734 cursor_pos = self._get_input_buffer_cursor_pos()
725 cursor_pos = self._get_input_buffer_cursor_pos()
735 code = self.input_buffer
726 code = self.input_buffer
736 # Send the metadata request to the kernel
727 # Send the metadata request to the kernel
737 msg_id = self.kernel_client.object_info(code, cursor_pos)
728 msg_id = self.kernel_client.inspect(code, cursor_pos)
738 pos = self._get_cursor().position()
729 pos = self._get_cursor().position()
739 self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos)
730 self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos)
740 return True
731 return True
@@ -57,7 +57,7 b' class QtShellChannelMixin(ChannelQObject):'
57 # Emitted when a reply has been received for the corresponding request type.
57 # Emitted when a reply has been received for the corresponding request type.
58 execute_reply = QtCore.Signal(object)
58 execute_reply = QtCore.Signal(object)
59 complete_reply = QtCore.Signal(object)
59 complete_reply = QtCore.Signal(object)
60 object_info_reply = QtCore.Signal(object)
60 inspect_reply = QtCore.Signal(object)
61 history_reply = QtCore.Signal(object)
61 history_reply = QtCore.Signal(object)
62
62
63 #---------------------------------------------------------------------------
63 #---------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now