Show More
@@ -41,7 +41,7 b' or using unicode completion:' | |||||
41 |
|
41 | |||
42 | Only valid Python identifiers will complete. Combining characters (like arrow or |
|
42 | Only valid Python identifiers will complete. Combining characters (like arrow or | |
43 | dots) are also available, unlike latex they need to be put after the their |
|
43 | dots) are also available, unlike latex they need to be put after the their | |
44 | counterpart that is to say, `F\\\\vec<tab>` is correct, not `\\\\vec<tab>F`. |
|
44 | counterpart that is to say, ``F\\\\vec<tab>`` is correct, not ``\\\\vec<tab>F``. | |
45 |
|
45 | |||
46 | Some browsers are known to display combining characters incorrectly. |
|
46 | Some browsers are known to display combining characters incorrectly. | |
47 |
|
47 |
@@ -199,19 +199,29 b' class ExecutionInfo(object):' | |||||
199 | store_history = False |
|
199 | store_history = False | |
200 | silent = False |
|
200 | silent = False | |
201 | shell_futures = True |
|
201 | shell_futures = True | |
|
202 | cell_id = None | |||
202 |
|
203 | |||
203 | def __init__(self, raw_cell, store_history, silent, shell_futures): |
|
204 | def __init__(self, raw_cell, store_history, silent, shell_futures, cell_id): | |
204 | self.raw_cell = raw_cell |
|
205 | self.raw_cell = raw_cell | |
205 | self.store_history = store_history |
|
206 | self.store_history = store_history | |
206 | self.silent = silent |
|
207 | self.silent = silent | |
207 | self.shell_futures = shell_futures |
|
208 | self.shell_futures = shell_futures | |
|
209 | self.cell_id = cell_id | |||
208 |
|
210 | |||
209 | def __repr__(self): |
|
211 | def __repr__(self): | |
210 | name = self.__class__.__qualname__ |
|
212 | name = self.__class__.__qualname__ | |
211 | raw_cell = ((self.raw_cell[:50] + '..') |
|
213 | raw_cell = ( | |
212 |
|
|
214 | (self.raw_cell[:50] + "..") if len(self.raw_cell) > 50 else self.raw_cell | |
213 | return '<%s object at %x, raw_cell="%s" store_history=%s silent=%s shell_futures=%s>' %\ |
|
215 | ) | |
214 | (name, id(self), raw_cell, self.store_history, self.silent, self.shell_futures) |
|
216 | return '<%s object at %x, raw_cell="%s" store_history=%s silent=%s shell_futures=%s cell_id=%s>' % ( | |
|
217 | name, | |||
|
218 | id(self), | |||
|
219 | raw_cell, | |||
|
220 | self.store_history, | |||
|
221 | self.silent, | |||
|
222 | self.shell_futures, | |||
|
223 | self.cell_id, | |||
|
224 | ) | |||
215 |
|
225 | |||
216 |
|
226 | |||
217 | class ExecutionResult(object): |
|
227 | class ExecutionResult(object): | |
@@ -2834,7 +2844,14 b' class InteractiveShell(SingletonConfigurable):' | |||||
2834 | self.showtraceback() |
|
2844 | self.showtraceback() | |
2835 | warn('Unknown failure executing module: <%s>' % mod_name) |
|
2845 | warn('Unknown failure executing module: <%s>' % mod_name) | |
2836 |
|
2846 | |||
2837 | def run_cell(self, raw_cell, store_history=False, silent=False, shell_futures=True): |
|
2847 | def run_cell( | |
|
2848 | self, | |||
|
2849 | raw_cell, | |||
|
2850 | store_history=False, | |||
|
2851 | silent=False, | |||
|
2852 | shell_futures=True, | |||
|
2853 | cell_id=None, | |||
|
2854 | ): | |||
2838 | """Run a complete IPython cell. |
|
2855 | """Run a complete IPython cell. | |
2839 |
|
2856 | |||
2840 | Parameters |
|
2857 | Parameters | |
@@ -2861,14 +2878,22 b' class InteractiveShell(SingletonConfigurable):' | |||||
2861 | result = None |
|
2878 | result = None | |
2862 | try: |
|
2879 | try: | |
2863 | result = self._run_cell( |
|
2880 | result = self._run_cell( | |
2864 |
raw_cell, store_history, silent, shell_futures |
|
2881 | raw_cell, store_history, silent, shell_futures, cell_id | |
|
2882 | ) | |||
2865 | finally: |
|
2883 | finally: | |
2866 | self.events.trigger('post_execute') |
|
2884 | self.events.trigger('post_execute') | |
2867 | if not silent: |
|
2885 | if not silent: | |
2868 | self.events.trigger('post_run_cell', result) |
|
2886 | self.events.trigger('post_run_cell', result) | |
2869 | return result |
|
2887 | return result | |
2870 |
|
2888 | |||
2871 | def _run_cell(self, raw_cell:str, store_history:bool, silent:bool, shell_futures:bool) -> ExecutionResult: |
|
2889 | def _run_cell( | |
|
2890 | self, | |||
|
2891 | raw_cell: str, | |||
|
2892 | store_history: bool, | |||
|
2893 | silent: bool, | |||
|
2894 | shell_futures: bool, | |||
|
2895 | cell_id: str, | |||
|
2896 | ) -> ExecutionResult: | |||
2872 | """Internal method to run a complete IPython cell.""" |
|
2897 | """Internal method to run a complete IPython cell.""" | |
2873 |
|
2898 | |||
2874 | # we need to avoid calling self.transform_cell multiple time on the same thing |
|
2899 | # we need to avoid calling self.transform_cell multiple time on the same thing | |
@@ -2888,6 +2913,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2888 | shell_futures=shell_futures, |
|
2913 | shell_futures=shell_futures, | |
2889 | transformed_cell=transformed_cell, |
|
2914 | transformed_cell=transformed_cell, | |
2890 | preprocessing_exc_tuple=preprocessing_exc_tuple, |
|
2915 | preprocessing_exc_tuple=preprocessing_exc_tuple, | |
|
2916 | cell_id=cell_id, | |||
2891 | ) |
|
2917 | ) | |
2892 |
|
2918 | |||
2893 | # run_cell_async is async, but may not actually need an eventloop. |
|
2919 | # run_cell_async is async, but may not actually need an eventloop. | |
@@ -2908,7 +2934,9 b' class InteractiveShell(SingletonConfigurable):' | |||||
2908 | try: |
|
2934 | try: | |
2909 | return runner(coro) |
|
2935 | return runner(coro) | |
2910 | except BaseException as e: |
|
2936 | except BaseException as e: | |
2911 | info = ExecutionInfo(raw_cell, store_history, silent, shell_futures) |
|
2937 | info = ExecutionInfo( | |
|
2938 | raw_cell, store_history, silent, shell_futures, cell_id | |||
|
2939 | ) | |||
2912 | result = ExecutionResult(info) |
|
2940 | result = ExecutionResult(info) | |
2913 | result.error_in_exec = e |
|
2941 | result.error_in_exec = e | |
2914 | self.showtraceback(running_compiled_code=True) |
|
2942 | self.showtraceback(running_compiled_code=True) | |
@@ -2964,7 +2992,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
2964 | shell_futures=True, |
|
2992 | shell_futures=True, | |
2965 | *, |
|
2993 | *, | |
2966 | transformed_cell: Optional[str] = None, |
|
2994 | transformed_cell: Optional[str] = None, | |
2967 | preprocessing_exc_tuple: Optional[Any] = None |
|
2995 | preprocessing_exc_tuple: Optional[Any] = None, | |
|
2996 | cell_id=None, | |||
2968 | ) -> ExecutionResult: |
|
2997 | ) -> ExecutionResult: | |
2969 | """Run a complete IPython cell asynchronously. |
|
2998 | """Run a complete IPython cell asynchronously. | |
2970 |
|
2999 | |||
@@ -2995,8 +3024,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2995 |
|
3024 | |||
2996 | .. versionadded:: 7.0 |
|
3025 | .. versionadded:: 7.0 | |
2997 | """ |
|
3026 | """ | |
2998 | info = ExecutionInfo( |
|
3027 | info = ExecutionInfo(raw_cell, store_history, silent, shell_futures, cell_id) | |
2999 | raw_cell, store_history, silent, shell_futures) |
|
|||
3000 | result = ExecutionResult(info) |
|
3028 | result = ExecutionResult(info) | |
3001 |
|
3029 | |||
3002 | if (not raw_cell) or raw_cell.isspace(): |
|
3030 | if (not raw_cell) or raw_cell.isspace(): |
@@ -92,8 +92,8 b' class Audio(DisplayObject):' | |||||
92 |
|
92 | |||
93 | From a File: |
|
93 | From a File: | |
94 |
|
94 | |||
95 |
>>> Audio(' |
|
95 | >>> Audio('IPython/lib/tests/test.wav') # doctest: +SKIP | |
96 |
>>> Audio(filename=' |
|
96 | >>> Audio(filename='IPython/lib/tests/test.wav') # doctest: +SKIP | |
97 |
|
97 | |||
98 | From Bytes: |
|
98 | From Bytes: | |
99 |
|
99 |
@@ -1,7 +1,7 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 | """ |
|
3 | """ | |
4 |
The :class:`~ |
|
4 | The :class:`~traitlets.config.application.Application` object for the command | |
5 | line :command:`ipython` program. |
|
5 | line :command:`ipython` program. | |
6 | """ |
|
6 | """ | |
7 |
|
7 |
@@ -17,22 +17,29 b' For example::' | |||||
17 | def __init__(self, ip): |
|
17 | def __init__(self, ip): | |
18 | self.shell = ip |
|
18 | self.shell = ip | |
19 | self.last_x = None |
|
19 | self.last_x = None | |
20 |
|
20 | |||
21 | def pre_execute(self): |
|
21 | def pre_execute(self): | |
22 | self.last_x = self.shell.user_ns.get('x', None) |
|
22 | self.last_x = self.shell.user_ns.get('x', None) | |
23 |
|
23 | |||
24 | def pre_run_cell(self, info): |
|
24 | def pre_run_cell(self, info): | |
25 |
print(' |
|
25 | print('info.raw_cell =', info.raw_cell) | |
26 |
|
26 | print('info.store_history =', info.store_history) | ||
|
27 | print('info.silent =', info.silent) | |||
|
28 | print('info.shell_futures =', info.shell_futures) | |||
|
29 | print('info.cell_id =', info.cell_id) | |||
|
30 | print(dir(info)) | |||
|
31 | ||||
27 | def post_execute(self): |
|
32 | def post_execute(self): | |
28 | if self.shell.user_ns.get('x', None) != self.last_x: |
|
33 | if self.shell.user_ns.get('x', None) != self.last_x: | |
29 | print("x changed!") |
|
34 | print("x changed!") | |
30 |
|
35 | |||
31 | def post_run_cell(self, result): |
|
36 | def post_run_cell(self, result): | |
32 | print('Cell code: "%s"' % result.info.raw_cell) |
|
37 | print('result.execution_count = ', result.execution_count) | |
33 |
if result.error_before_exec |
|
38 | print('result.error_before_exec = ', result.error_before_exec) | |
34 |
|
|
39 | print('result.error_in_exec = ', result.error_in_exec) | |
35 |
|
40 | print('result.info = ', result.info) | ||
|
41 | print('result.result = ', result.result) | |||
|
42 | ||||
36 | def load_ipython_extension(ip): |
|
43 | def load_ipython_extension(ip): | |
37 | vw = VarWatcher(ip) |
|
44 | vw = VarWatcher(ip) | |
38 | ip.events.register('pre_execute', vw.pre_execute) |
|
45 | ip.events.register('pre_execute', vw.pre_execute) | |
@@ -40,6 +47,13 b' For example::' | |||||
40 | ip.events.register('post_execute', vw.post_execute) |
|
47 | ip.events.register('post_execute', vw.post_execute) | |
41 | ip.events.register('post_run_cell', vw.post_run_cell) |
|
48 | ip.events.register('post_run_cell', vw.post_run_cell) | |
42 |
|
49 | |||
|
50 | .. versionadded:: 8.3 | |||
|
51 | ||||
|
52 | Since IPython 8.3 and ipykernel 6.12.1, the ``info`` objects in the callback | |||
|
53 | now have a the ``cell_id`` that will be set to the value sent by the | |||
|
54 | frontened, when those send it. | |||
|
55 | ||||
|
56 | ||||
43 |
|
57 | |||
44 | Events |
|
58 | Events | |
45 | ====== |
|
59 | ====== |
@@ -3,6 +3,14 b'' | |||||
3 | ============ |
|
3 | ============ | |
4 |
|
4 | |||
5 |
|
5 | |||
|
6 | .. _version 8.3.0: | |||
|
7 | ||||
|
8 | IPython 8.3.0 | |||
|
9 | ------------- | |||
|
10 | ||||
|
11 | - :ghpull:`13600`, ``pre_run_*``-hooks will now have a ``cell_id`` attribute on | |||
|
12 | the info object when frontend provide it. | |||
|
13 | ||||
6 | .. _version 8.2.0: |
|
14 | .. _version 8.2.0: | |
7 |
|
15 | |||
8 | IPython 8.2.0 |
|
16 | IPython 8.2.0 |
General Comments 0
You need to be logged in to leave comments.
Login now