This project has moved. For the latest updates, please go here.

Embedded interactives

Nov 3, 2014 at 3:41 PM

I deal a lot with an application that embeds python and has a terrible console interface. At one point I wrote a custom shell running in a separate process and rerouting stdin/out/err, but it still lacks a lot of the lovely featureses that the Python Tools-interactives have, most notably the Intellisense part.

What would be involved in turning my out-of-process shell into a Python Tools interactive, preferably with support for being the target of "send to interactive"?
Nov 3, 2014 at 4:43 PM
What you can do is set up a custom environment (easy) and create an interactive execution mode (not so easy).

First, you'll want to look at - specifically the IPythonBackend class - as this is fairly similar to what you'll need to do to redirect stdin/out/err. You'll want your own file like this that can launch and/or connect to an instance of your application.

To register your new backend so that it appears in VS (in the Interactive Options, which currently has "IPython" and "IPython w/o pylab" modes), you'll need to create [HKCU\Software\VisualStudio\12.0_Config\PythonTools\ReplExecutionModes\{guid}] and put in string values for Type and FriendlyName.

Type is the name of the Python backend class - for IPython mode, this is visualstudio_ipython_repl.IPythonBackend, so I'd expect yours to be similar. I don't think it matters where the Python file is located as long as it's importable, but putting it in our install directory alongside the others is.

You'll want a custom environment inside PTVS so that you can set the library path correctly, as this will help with IntelliSense, but there are also get_signatures and get_members functions on the backend so you can generate IntelliSense "live". You can modify Interactive Options for your environment to use your own backend, and then you'll get all the rest of the PTVS features.

As far as I know, you're the first person outside our group to attempt this, so we'll be very interested in how it goes. Feel free to ask for more help when you run into trouble. :)
Nov 4, 2014 at 7:04 AM
Thanks for the detailed road map. I'll get started failing as soon as I can and then I'll be back!