Skip to content

Add -m, -e and -d filters to %logstart 🤖🤖 - #15401

Open
costajohnt wants to merge 1 commit into
ipython:mainfrom
costajohnt:feat/logstart-filters
Open

costajohnt wants to merge 1 commit into
ipython:mainfrom
costajohnt:feat/logstart-filters

Conversation

@costajohnt

Copy link
Copy Markdown

Closes #15344

%logstart gets three flags for keeping a session log that replays cleanly:

  • -m leaves out cells containing IPython special commands (magics, shell escapes, help lookups), i.e. input that IPython rewrites into get_ipython() calls.
  • -e leaves out input that raised. The entry, and its -o output, is held until post_run_cell reports the result. Pending entries are a stack, so cells run from inside a cell (%%capture, %rerun, %paste) are kept; an inner cell is written when it finishes, so it precedes the outer one.
  • -d leaves out input that was already logged in the session. An errored entry dropped by -e does not count as logged.

They combine, for example %logstart -med session.py. %logstate reports them.

Two limits, both stated in the docstring: the filters apply to input entered after %logstart (the history written when the log starts is not filtered), and -m works per cell rather than per line, since raw-mode lines do not map one-to-one onto the transformed cell.

Docs: the magic docstring, docs/source/interactive/reference.rst, and a whatsnew/pr file.

Tests in tests/test_logger.py: each flag on its own, -rm, -oe output ordering, a nested %%capture cell under -e, -ed together, -d resetting between logs, a check that magics are still logged without -m, and %logstate output.

🤖🤖

Let %logstart leave out cells with IPython special commands, input that
raised, and input already logged, so a session log replays cleanly.
Errored input (and its logged output) is held until post_run_cell reports
the result; pending entries are a stack so cells run from inside a cell
(%%capture, %rerun, %paste) are kept.

Closes ipython#15344

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature suggestion] Allow the magic command "%logstart" to filter what should be added to the history.

1 participant