##// END OF EJS Templates
Merge pull request #13628 from Carreau/auto-backport-of-pr-13600-on-7.x...
Matthias Bussonnier -
r27631:c3f199f9 merge
parent child Browse files
Show More
@@ -41,7 +41,7 b' or using unicode completion:'
41 41
42 42 Only valid Python identifiers will complete. Combining characters (like arrow or
43 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 46 Some browsers are known to display combining characters incorrectly.
47 47
@@ -297,19 +297,29 b' class ExecutionInfo(object):'
297 297 store_history = False
298 298 silent = False
299 299 shell_futures = True
300 cell_id = None
300 301
301 def __init__(self, raw_cell, store_history, silent, shell_futures):
302 def __init__(self, raw_cell, store_history, silent, shell_futures, cell_id):
302 303 self.raw_cell = raw_cell
303 304 self.store_history = store_history
304 305 self.silent = silent
305 306 self.shell_futures = shell_futures
307 self.cell_id = cell_id
306 308
307 309 def __repr__(self):
308 310 name = self.__class__.__qualname__
309 raw_cell = ((self.raw_cell[:50] + '..')
310 if len(self.raw_cell) > 50 else self.raw_cell)
311 return '<%s object at %x, raw_cell="%s" store_history=%s silent=%s shell_futures=%s>' %\
312 (name, id(self), raw_cell, self.store_history, self.silent, self.shell_futures)
311 raw_cell = (
312 (self.raw_cell[:50] + "..") if len(self.raw_cell) > 50 else self.raw_cell
313 )
314 return '<%s object at %x, raw_cell="%s" store_history=%s silent=%s shell_futures=%s cell_id=%s>' % (
315 name,
316 id(self),
317 raw_cell,
318 self.store_history,
319 self.silent,
320 self.shell_futures,
321 self.cell_id,
322 )
313 323
314 324
315 325 class ExecutionResult(object):
@@ -2928,7 +2938,14 b' class InteractiveShell(SingletonConfigurable):'
2928 2938 self.showtraceback()
2929 2939 warn('Unknown failure executing module: <%s>' % mod_name)
2930 2940
2931 def run_cell(self, raw_cell, store_history=False, silent=False, shell_futures=True):
2941 def run_cell(
2942 self,
2943 raw_cell,
2944 store_history=False,
2945 silent=False,
2946 shell_futures=True,
2947 cell_id=None,
2948 ):
2932 2949 """Run a complete IPython cell.
2933 2950
2934 2951 Parameters
@@ -2955,14 +2972,22 b' class InteractiveShell(SingletonConfigurable):'
2955 2972 result = None
2956 2973 try:
2957 2974 result = self._run_cell(
2958 raw_cell, store_history, silent, shell_futures)
2975 raw_cell, store_history, silent, shell_futures, cell_id
2976 )
2959 2977 finally:
2960 2978 self.events.trigger('post_execute')
2961 2979 if not silent:
2962 2980 self.events.trigger('post_run_cell', result)
2963 2981 return result
2964 2982
2965 def _run_cell(self, raw_cell:str, store_history:bool, silent:bool, shell_futures:bool):
2983 def _run_cell(
2984 self,
2985 raw_cell: str,
2986 store_history: bool,
2987 silent: bool,
2988 shell_futures: bool,
2989 cell_id: str,
2990 ) -> ExecutionResult:
2966 2991 """Internal method to run a complete IPython cell."""
2967 2992
2968 2993 # we need to avoid calling self.transform_cell multiple time on the same thing
@@ -2982,6 +3007,7 b' class InteractiveShell(SingletonConfigurable):'
2982 3007 shell_futures=shell_futures,
2983 3008 transformed_cell=transformed_cell,
2984 3009 preprocessing_exc_tuple=preprocessing_exc_tuple,
3010 cell_id=cell_id,
2985 3011 )
2986 3012
2987 3013 # run_cell_async is async, but may not actually need an eventloop.
@@ -3002,7 +3028,9 b' class InteractiveShell(SingletonConfigurable):'
3002 3028 try:
3003 3029 return runner(coro)
3004 3030 except BaseException as e:
3005 info = ExecutionInfo(raw_cell, store_history, silent, shell_futures)
3031 info = ExecutionInfo(
3032 raw_cell, store_history, silent, shell_futures, cell_id
3033 )
3006 3034 result = ExecutionResult(info)
3007 3035 result.error_in_exec = e
3008 3036 self.showtraceback(running_compiled_code=True)
@@ -3060,7 +3088,8 b' class InteractiveShell(SingletonConfigurable):'
3060 3088 shell_futures=True,
3061 3089 *,
3062 3090 transformed_cell: Optional[str] = None,
3063 preprocessing_exc_tuple: Optional[Any] = None
3091 preprocessing_exc_tuple: Optional[Any] = None,
3092 cell_id=None,
3064 3093 ) -> ExecutionResult:
3065 3094 """Run a complete IPython cell asynchronously.
3066 3095
@@ -3091,8 +3120,7 b' class InteractiveShell(SingletonConfigurable):'
3091 3120
3092 3121 .. versionadded:: 7.0
3093 3122 """
3094 info = ExecutionInfo(
3095 raw_cell, store_history, silent, shell_futures)
3123 info = ExecutionInfo(raw_cell, store_history, silent, shell_futures, cell_id)
3096 3124 result = ExecutionResult(info)
3097 3125
3098 3126 if (not raw_cell) or raw_cell.isspace():
@@ -1,7 +1,7 b''
1 1 #!/usr/bin/env python
2 2 # encoding: utf-8
3 3 """
4 The :class:`~IPython.core.application.Application` object for the command
4 The :class:`~traitlets.config.application.Application` object for the command
5 5 line :command:`ipython` program.
6 6 """
7 7
@@ -17,22 +17,29 b' For example::'
17 17 def __init__(self, ip):
18 18 self.shell = ip
19 19 self.last_x = None
20
20
21 21 def pre_execute(self):
22 22 self.last_x = self.shell.user_ns.get('x', None)
23
23
24 24 def pre_run_cell(self, info):
25 print('Cell code: "%s"' % info.raw_cell)
26
25 print('info.raw_cell =', info.raw_cell)
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 32 def post_execute(self):
28 33 if self.shell.user_ns.get('x', None) != self.last_x:
29 34 print("x changed!")
30
35
31 36 def post_run_cell(self, result):
32 print('Cell code: "%s"' % result.info.raw_cell)
33 if result.error_before_exec:
34 print('Error before execution: %s' % result.error_before_exec)
35
37 print('result.execution_count = ', result.execution_count)
38 print('result.error_before_exec = ', result.error_before_exec)
39 print('result.error_in_exec = ', result.error_in_exec)
40 print('result.info = ', result.info)
41 print('result.result = ', result.result)
42
36 43 def load_ipython_extension(ip):
37 44 vw = VarWatcher(ip)
38 45 ip.events.register('pre_execute', vw.pre_execute)
@@ -40,6 +47,13 b' For example::'
40 47 ip.events.register('post_execute', vw.post_execute)
41 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 58 Events
45 59 ======
General Comments 0
You need to be logged in to leave comments. Login now