##// END OF EJS Templates
Revert "Update README to use optional dependency over requirements.txt"...
Revert "Update README to use optional dependency over requirements.txt" In 4ab4de3bb (Update README to use optional dependency over requirements.txt, 2022-09-06), docs/README.rst was changed to suggest installing the requirements for the documentation build using 'pip install .[doc] -U' instead of using docs/requirements.txt. This works for a first build but since it is not an editable install, any changes to the docstrings are not reflected in the generated API section in subsequent builds, since Sphinx's autodoc extensions looks at installed modules only. Revert that commit, going back to suggesting 'pip install -U -r docs/requirements.txt'. The requirements file itself consists of '-e .[doc]' since 95de1fe40 (Move documentation requirements to setup.cfg, 2022-09-06) (the parent of the commit we are reverting), so this does not change the list of installed packages. This reverts commit 4ab4de3bbf08805262e4b67957faf2e2c588e382.

File last commit:

r27617:f3957c0f
r28183:af5f1156
Show More
callbacks.rst
113 lines | 3.8 KiB | text/x-rst | RstLexer
Min RK
document existing events
r21899 .. _events:
.. _callbacks:
==============
IPython Events
==============
Thomas Kluyver
Document new callbacks system
r15604
Extension code can register callbacks functions which will be called on specific
events within the IPython code. You can see the current list of available
callbacks, and the parameters that will be passed with each, in the callback
Jeremy Sikes
Fix doc :ref: target...
r24029 prototype functions defined in :mod:`IPython.core.events`.
Thomas Kluyver
Document new callbacks system
r15604
Thomas Kluyver
callbacks -> events in docs
r15613 To register callbacks, use :meth:`IPython.core.events.EventManager.register`.
Thomas Kluyver
Document new callbacks system
r15604 For example::
class VarWatcher(object):
def __init__(self, ip):
self.shell = ip
self.last_x = None
Matthias Bussonnier
docs
r27617
Fabio Niephaus
Rename ExecutionRequest to ExecutionInfo; refactor
r23997 def pre_execute(self):
Thomas Kluyver
Document new callbacks system
r15604 self.last_x = self.shell.user_ns.get('x', None)
Matthias Bussonnier
docs
r27617
Fabio Niephaus
Rename ExecutionRequest to ExecutionInfo; refactor
r23997 def pre_run_cell(self, info):
Matthias Bussonnier
docs
r27617 print('info.raw_cell =', info.raw_cell)
print('info.store_history =', info.store_history)
print('info.silent =', info.silent)
print('info.shell_futures =', info.shell_futures)
print('info.cell_id =', info.cell_id)
print(dir(info))
Fabio Niephaus
Rename ExecutionRequest to ExecutionInfo; refactor
r23997 def post_execute(self):
Thomas Kluyver
Document new callbacks system
r15604 if self.shell.user_ns.get('x', None) != self.last_x:
print("x changed!")
Matthias Bussonnier
docs
r27617
Fabio Niephaus
Rename ExecutionRequest to ExecutionInfo; refactor
r23997 def post_run_cell(self, result):
Matthias Bussonnier
docs
r27617 print('result.execution_count = ', result.execution_count)
print('result.error_before_exec = ', result.error_before_exec)
print('result.error_in_exec = ', result.error_in_exec)
print('result.info = ', result.info)
print('result.result = ', result.result)
Thomas Kluyver
Document new callbacks system
r15604 def load_ipython_extension(ip):
vw = VarWatcher(ip)
Thomas Kluyver
callbacks -> events in docs
r15613 ip.events.register('pre_execute', vw.pre_execute)
Fabio Niephaus
Rename ExecutionRequest to ExecutionInfo; refactor
r23997 ip.events.register('pre_run_cell', vw.pre_run_cell)
Thomas Kluyver
callbacks -> events in docs
r15613 ip.events.register('post_execute', vw.post_execute)
Fabio Niephaus
Rename ExecutionRequest to ExecutionInfo; refactor
r23997 ip.events.register('post_run_cell', vw.post_run_cell)
Thomas Kluyver
Document new callbacks system
r15604
Matthias Bussonnier
docs
r27617 .. versionadded:: 8.3
Since IPython 8.3 and ipykernel 6.12.1, the ``info`` objects in the callback
now have a the ``cell_id`` that will be set to the value sent by the
frontened, when those send it.
Thomas Kluyver
Add note about experimental API
r15606
Min RK
document existing events
r21899 Events
======
These are the events IPython will emit. Callbacks will be passed no arguments, unless otherwise specified.
shell_initialized
-----------------
.. code-block:: python
def shell_initialized(ipython):
...
This event is triggered only once, at the end of setting up IPython.
Extensions registered to load by default as part of configuration can use this to execute code to finalize setup.
Callbacks will be passed the InteractiveShell instance.
pre_run_cell
------------
``pre_run_cell`` fires prior to interactive execution (e.g. a cell in a notebook).
It can be used to note the state prior to execution, and keep track of changes.
Fabio Niephaus
Rename ExecutionRequest to ExecutionInfo; refactor
r23997 An object containing information used for the code execution is provided as an argument.
Min RK
document existing events
r21899
pre_execute
-----------
``pre_execute`` is like ``pre_run_cell``, but is triggered prior to *any* execution.
Sometimes code can be executed by libraries, etc. which
skipping the history/display mechanisms, in which cases ``pre_run_cell`` will not fire.
post_run_cell
-------------
Fabio Niephaus
Ensure `function` is actually a function....
r23984 ``post_run_cell`` runs after interactive execution (e.g. a cell in a notebook).
It can be used to cleanup or notify or perform operations on any side effects produced during execution.
For instance, the inline matplotlib backend uses this event to display any figures created but not explicitly displayed during the course of the cell.
Fabio Niephaus
Ensure post event callbacks are always called....
r23982 The object which will be returned as the execution result is provided as an
argument.
Min RK
document existing events
r21899
post_execute
------------
The same as ``pre_execute``, ``post_execute`` is like ``post_run_cell``,
Fabio Niephaus
Ensure post event callbacks are always called....
r23982 but fires for *all* executions, not just interactive ones.
Fabio Niephaus
Add support for "finally" event callbacks....
r23909
Thomas Kluyver
Add note about experimental API
r15606
Thomas Kluyver
Document new callbacks system
r15604 .. seealso::
Module :mod:`IPython.core.hooks`
The older 'hooks' system allows end users to customise some parts of
IPython's behaviour.
:doc:`inputtransforms`
By registering input transformers that don't change code, you can monitor
what is being executed.