bot icon indicating copy to clipboard operation
bot copied to clipboard

Add an IPython mode to eval

Open ionite34 opened this issue 3 years ago • 1 comments

Current working command schemes:

  • !eval -ipython
  • !e -i

Support IPython mode for eval with code blocks as "cells". Matplotlib will use a custom backend for show() which writes a png file to the output folder for upload.

This will use the ipykernel backend with full support for ipython magic commands like %%time

We can also inject custom exec tasks, imports, or custom ipython macros and magic commands via the ipython api.

Most of the runtime wrapper can be sent from the bot side, we will just require snekbox to add the ipython package to deployment.

Depends on

  • https://github.com/python-discord/snekbox/pull/159
  • https://github.com/python-discord/bot/pull/2326
  • Add ipython to our snekbox deployment venv

Proof of concept

image

  • Since IPython errors are colored with ANSI codes, we can use an ansi codeblock to render them

image

ionite34 avatar Dec 23 '22 02:12 ionite34

I wonder if this needs to actually be a separate option. On the surface we could just replace the behavior of concatenating several blocks into this. Then again not everyone might find ipython intuitive without prior experience. We could make it default to a usual run if there's up to one codeblocks, and an ipython run otherwise. The error coloring is a very nice bonus.

mbaruh avatar Feb 27 '23 14:02 mbaruh