From c08bdde70687ec555c49af6db237bbb133408de4 2014-05-08 21:05:02 From: MinRK Date: 2014-05-08 21:05:02 Subject: [PATCH] updates per review - two-part protocol version (5.0) - default value for cursor_pos is end of code - docs, comment, and docstring touchups --- diff --git a/IPython/core/page.py b/IPython/core/page.py index c39569e..518b6f9 100644 --- a/IPython/core/page.py +++ b/IPython/core/page.py @@ -133,7 +133,10 @@ def _detect_screen_size(screen_lines_def): #screen_cols,'columns.' # dbg def page(strng, start=0, screen_lines=0, pager_cmd=None): - """Print a string, piping through a pager after a certain length. + """Display a string, piping through a pager after a certain length. + + strng can be a mime-bundle dict, supplying multiple representations, + keyed by mime-type. The screen_lines parameter specifies the number of *usable* lines of your terminal screen (total lines minus lines you need to reserve to show other diff --git a/IPython/core/release.py b/IPython/core/release.py index 5030263..822b940 100644 --- a/IPython/core/release.py +++ b/IPython/core/release.py @@ -40,8 +40,8 @@ version = __version__ # backwards compatibility name version_info = (_version_major, _version_minor, _version_patch, _version_extra) # Change this when incrementing the kernel protocol version -kernel_protocol_version_info = (5, 0, 0) -kernel_protocol_version = "%i.%i.%i" % kernel_protocol_version_info +kernel_protocol_version_info = (5, 0) +kernel_protocol_version = "%i.%i" % kernel_protocol_version_info description = "IPython: Productive Interactive Computing" diff --git a/IPython/html/static/notebook/js/tooltip.js b/IPython/html/static/notebook/js/tooltip.js index 066f709..76d1ec0 100644 --- a/IPython/html/static/notebook/js/tooltip.js +++ b/IPython/html/static/notebook/js/tooltip.js @@ -251,11 +251,6 @@ var IPython = (function (IPython) { this.reset_tabs_function (cell, text); } - // don't do anything if line begins with '(' or is empty - // if (text === "" || text === "(") { - // return; - // } - this.tabs_functions[this._consecutive_counter](cell, text, cursor_pos); // then if we are at the end of list function, reset diff --git a/IPython/kernel/channels.py b/IPython/kernel/channels.py index 73511f1..4d875ba 100644 --- a/IPython/kernel/channels.py +++ b/IPython/kernel/channels.py @@ -270,7 +270,7 @@ class ShellChannel(ZMQSocketChannel): self._queue_send(msg) return msg['header']['msg_id'] - def complete(self, code, cursor_pos=0, block=None): + def complete(self, code, cursor_pos=None): """Tab complete text in the kernel's namespace. Parameters @@ -280,17 +280,20 @@ class ShellChannel(ZMQSocketChannel): Can be anything between a variable name and an entire cell. cursor_pos : int, optional The position of the cursor in the block of code where the completion was requested. + Default: ``len(code)`` Returns ------- The msg_id of the message sent. """ + if cursor_pos is None: + cursor_pos = len(code) content = dict(code=code, cursor_pos=cursor_pos) msg = self.session.msg('complete_request', content) self._queue_send(msg) return msg['header']['msg_id'] - def inspect(self, code, cursor_pos=0, detail_level=0): + def inspect(self, code, cursor_pos=None, 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. @@ -302,6 +305,7 @@ class ShellChannel(ZMQSocketChannel): Can be anything between a variable name and an entire cell. cursor_pos : int, optional The position of the cursor in the block of code where the info was requested. + Default: ``len(code)`` detail_level : int, optional The level of detail for the introspection (0-2) @@ -309,6 +313,8 @@ class ShellChannel(ZMQSocketChannel): ------- The msg_id of the message sent. """ + if cursor_pos is None: + cursor_pos = len(code) content = dict(code=code, cursor_pos=cursor_pos, detail_level=detail_level, ) diff --git a/IPython/kernel/inprocess/channels.py b/IPython/kernel/inprocess/channels.py index 8a7459b..25eb1a0 100644 --- a/IPython/kernel/inprocess/channels.py +++ b/IPython/kernel/inprocess/channels.py @@ -94,13 +94,17 @@ class InProcessShellChannel(InProcessChannel): self._dispatch_to_kernel(msg) return msg['header']['msg_id'] - def complete(self, code, cursor_pos=0): + def complete(self, code, cursor_pos=None): + if cursor_pos is None: + cursor_pos = len(code) content = dict(code=code, cursor_pos=cursor_pos) msg = self.client.session.msg('complete_request', content) self._dispatch_to_kernel(msg) return msg['header']['msg_id'] - def inspect(self, code, cursor_pos=0, detail_level=0): + def inspect(self, code, cursor_pos=None, detail_level=0): + if cursor_pos is None: + cursor_pos = len(code) content = dict(code=code, cursor_pos=cursor_pos, detail_level=detail_level, ) diff --git a/IPython/kernel/tests/test_message_spec.py b/IPython/kernel/tests/test_message_spec.py index 0850a1d..e1080e9 100644 --- a/IPython/kernel/tests/test_message_spec.py +++ b/IPython/kernel/tests/test_message_spec.py @@ -59,11 +59,20 @@ class Reference(HasTraits): except TraitError as e: assert False, str(e) + class Version(Unicode): + def __init__(self, *args, **kwargs): + self.min = kwargs.pop('min', None) + self.max = kwargs.pop('max', None) + kwargs['default_value'] = self.min + super(Version, self).__init__(*args, **kwargs) + def validate(self, obj, value): - min_version = self.default_value - if V(value) < V(min_version): - raise TraitError("bad version: %s < %s" % (value, min_version)) + if self.min and V(value) < V(self.min): + raise TraitError("bad version: %s < %s" % (value, self.min)) + if self.max and (V(value) > V(self.max)): + raise TraitError("bad version: %s > %s" % (value, self.max)) + class RMessage(Reference): msg_id = Unicode() @@ -83,9 +92,9 @@ class RHeader(Reference): msg_type = Unicode() session = Unicode() username = Unicode() - version = Version('5.0') + version = Version(min='5.0') -mime_pat = re.compile(r'\w+/\w+') +mime_pat = re.compile(r'^[\w\-\+\.]+/[\w\-\+\.]+$') class MimeBundle(Reference): metadata = Dict() @@ -143,10 +152,10 @@ class CompleteReply(Reference): class KernelInfoReply(Reference): - protocol_version = Version('5.0') + protocol_version = Version(min='5.0') implementation = Unicode('ipython') - implementation_version = Version('2.1') - language_version = Version('2.7') + implementation_version = Version(min='2.1') + language_version = Version(min='2.7') language = Unicode('python') banner = Unicode() diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py index 6e23029..09ce934 100755 --- a/IPython/kernel/zmq/ipkernel.py +++ b/IPython/kernel/zmq/ipkernel.py @@ -369,9 +369,13 @@ class Kernel(Configurable): getpass.getpass = self._save_getpass def set_parent(self, ident, parent): - """Record the parent state + """Set the current parent_header - For associating side effects with their requests. + Side effects (IOPub messages) and replies are associated with + the request that caused them via the parent_header. + + The parent identity is used to route input_request messages + on the stdin channel. """ self._parent_ident = ident self._parent_header = parent @@ -617,9 +621,6 @@ class Kernel(Configurable): shell = self.shell shell.set_parent(parent) - # execute_input_msg = self.session.msg(u'execute_input',{u'code':code}, parent=parent) - # self.iopub_socket.send(execute_input_msg) - # self.session.send(self.iopub_socket, u'execute_input', {u'code':code},parent=parent) md = self._make_metadata(parent['metadata']) try: working = shell.user_ns diff --git a/IPython/qt/console/frontend_widget.py b/IPython/qt/console/frontend_widget.py index 00de669..62d7332 100644 --- a/IPython/qt/console/frontend_widget.py +++ b/IPython/qt/console/frontend_widget.py @@ -512,10 +512,6 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): info = self._request_info.get('call_tip') if info and info.id == rep['parent_header']['msg_id'] and \ info.pos == cursor.position(): - # Get the information for a call tip. For now we format the call - # line as string, later we can pass False to format_call and - # syntax-highlight it ourselves for nicer formatting in the - # calltip. content = rep['content'] if content.get('status') == 'ok': self._call_tip_widget.show_inspect_data(content) diff --git a/docs/source/development/execution.rst b/docs/source/development/execution.rst index 8aa2a4a..8350c04 100644 --- a/docs/source/development/execution.rst +++ b/docs/source/development/execution.rst @@ -10,14 +10,12 @@ The execution of use code consists of the following phases: 3. Execute the ``code`` field, see below for details. 4. If execution succeeds, expressions in ``user_expressions`` are computed. This ensures that any error in the expressions don't affect the main code execution. -5. Fire the post_execute eventCall any method registered with :meth:`register_post_execute`. +5. Fire the post_execute event. -.. warning:: +.. seealso:: + + :doc:`config/callbacks` - The API for running code before/after the main code block is likely to - change soon. Both the ``pre_runcode_hook`` and the - :meth:`register_post_execute` are susceptible to modification, as we find a - consistent model for both. To understand how the ``code`` field is executed, one must know that Python code can be compiled in one of three modes (controlled by the ``mode`` argument @@ -64,7 +62,3 @@ execution in 'single' mode, and then: unit. -Errors in any registered post_execute functions are reported, -and the failing function is removed from the post_execution set so that it does -not continue triggering failures. - diff --git a/docs/source/development/messaging.rst b/docs/source/development/messaging.rst index 42764e1..6c145c4 100644 --- a/docs/source/development/messaging.rst +++ b/docs/source/development/messaging.rst @@ -9,7 +9,7 @@ Versioning ========== The IPython message specification is versioned independently of IPython. -The current version of the specification is 5.0.0. +The current version of the specification is 5.0. Introduction @@ -107,7 +107,7 @@ A message is defined by the following four-dictionary structure:: # All recognized message type strings are listed below. 'msg_type' : str, # the message protocol version - 'version' : '5.0.0', + 'version' : '5.0', }, # In a chain of messages, the header from the parent is copied so that @@ -122,7 +122,7 @@ A message is defined by the following four-dictionary structure:: 'content' : dict, } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``version`` key added to the header. @@ -281,7 +281,7 @@ Message type: ``execute_request``:: 'allow_stdin' : True, } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``user_variables`` removed, because it is redundant with user_expressions. @@ -366,7 +366,7 @@ When status is 'ok', the following extra fields are present:: 'user_expressions' : dict, } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``user_variables`` is removed, use user_expressions instead. @@ -433,11 +433,11 @@ Message type: ``inspect_request``:: 'detail_level' : 0 or 1, } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``object_info_request`` renamed to ``inspect_request``. -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``name`` key replaced with ``code`` and ``cursor_pos``, moving the lexing responsibility to the kernel. @@ -457,11 +457,11 @@ Message type: ``inspect_reply``:: 'metadata' : dict, } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``object_info_reply`` renamed to ``inspect_reply``. -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 Reply is changed from structured data to a mime bundle, allowing formatting decisions to be made by the kernel. @@ -480,7 +480,7 @@ Message type: ``complete_request``:: 'cursor_pos' : int, } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``line``, ``block``, and ``text`` keys are removed in favor of a single ``code`` for context. Lexing is up to the kernel. @@ -507,7 +507,7 @@ Message type: ``complete_reply``:: 'status' : 'ok' } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 - ``matched_text`` is removed in favor of ``cursor_start`` and ``cursor_end``. - ``metadata`` is added for extended information. @@ -638,15 +638,15 @@ Message type: ``kernel_info_reply``:: 'banner' : str, } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 Versions changed from lists of integers to strings. -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``ipython_version`` is removed. -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``implementation``, ``implementation_version``, and ``banner`` keys are added. @@ -760,7 +760,7 @@ of images:: } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 `application/json` data should be unpacked JSON data, not double-serialized as a JSON string. @@ -822,7 +822,7 @@ Message type: ``execute_input``:: 'execution_count' : int } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``pyin`` is renamed to ``execute_input``. @@ -868,7 +868,7 @@ Message type: ``error``:: # except the 'status' field is omitted. } -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``pyerr`` renamed to ``error`` @@ -937,7 +937,7 @@ Message type: ``input_reply``:: When ``password`` is True, the frontend should not echo the input as it is entered. -.. versionchanged:: 5.0.0 +.. versionchanged:: 5.0 ``password`` key added.