[IronPython] Embedding IPython Shell into IronPython
davew252 at tx.rr.com
Tue Feb 15 06:31:29 PST 2011
No problem. Enjoyed working on it. Now, the even better news.
PyReadline HAS BEEN ported to IronPython! ;-)
So IPython could very likely be made fully functional... with a bit of work.
From what I gather so far, you may still have to compile your own
version of IronPython as per the discussion therein, but, I just need to
get some more time to play with this.
I got side-tracked over the weekend um, 'reflecting' on what the
internals of Sho might look like, if you could see them, if you get my
drift... since the engine source code is not available... It seems the
EmbeddedSho class always starts up a new PythoneEngine regardless, and
they hardcode the references to version 2.6.2, I believe...
So, that'll take a bit of fiddling to embed it. Hope to get back on that
Also, spent a lot of time re-learning Ruby and messing with Cucumber -
need to try and get some kind of BDD acceptance-criteria testing
automation thing going as simply as possible, but looks like Cucumber
only works (best) with Rails. Again - so much to learn, so little time...
BTW, it looks to me like IronRuby has made GREAT strides in the last
couple years. Excellent work guys!!! Thanks!
That's about it for now. I really do like IPython. I want to get that
going, with the PyReadline support. Soon... very soon... ;-)
On 2/15/2011 3:43 AM, Federico Vaggi wrote:
> Hey Dave,
> thanks a lot for all the help. Without the tab completion/colour it
> seems like this is a lot of work for a very plain shell, and Sho looks
> like a much better option - I played around with it a fair bit (it
> seems better than the plain IronPython console) but I haven't found
> much on how to embed it yet. I'll head over to their forums and see
> if there is something I am missing.
> On 11/02/2011 05:09, Dave Wald wrote:
>> First off, Thanks to all the developers! 2.7b1 and b2 have been
>> excellent so far, at least as far as my current needs go. The new
>> subprocess module is great. Came just in time. Great work!
>> Your post caught my eye, as I also like good embeddable console apps.
>> Hadn't used IPython before so I downloaded it and played with it.
>> Installed the PyReadline library as recommended to get all the
>> command line goodies. Nice.
>> OK, so then, of course, I had to try it in IronPython, and
>> immediately hit the same issues you did, with almost the exact same
>> traceback info, etc.
>> So, I fired up the excellent Tools for Visual Studio 2010 and created
>> a little project to embed the shell and call it from my running
>> IPyScratchPad app (with a WinForms dll to house the form) and traced
>> thru it in the Debugger.
>> Long story short, I found the major issue (and a couple of minor
>> ones) and got it to run.
>> Now, I'm pretty sure Readline has not been ported to IronPython yet,
>> and you know it requires pywin32. So that is not going to run under
>> But the rest of it seems to be working ok. No tab completion or
>> colorization but...
>> Here's what I did (ultimately) to get it to run:
>> First of all, copied the whole IPython folder structure over under
>> "C:\Program Files (x86)\IronPython 2.7\Lib\site-packages".
>> I created a new Scripts folder under "C:\Program Files
>> (x86)\IronPython 2.7", as IPython creates under Python 2.6.
>> Copied thefollowing two files into it:
>> Modified ipython.bat file to read:
>> cd "C:\Program Files (x86)\IronPython 2.7"
>> ipy.exe -X:Frames .\Scripts\ipython.py %*
>> Double-clicking the bat file will now start up the IPython console
>> running in IPy.exe.
>> Notice the " -X:Frames " option specified. That is the major key to
>> Turns out, IronPython does not enable sys._getframe by default, which
>> is required by IPython.
>> Note (from the Python doc):
>> Return a frame object from the call stack. If optional integer depth
>> is given, return the frame object that many calls below the top of
>> the stack. If that is deeper than the call stack, ValueError is
>> raised. The default for depth is zero, returning the frame at the top
>> of the call stack.
>> CPython implementation detail: This function should be used for
>> internal and specialized purposes only. It is not guaranteed to exist
>> in all implementations of Python.
>> Found a post on StackOverflow, with a reply by Jeff Hardy about this,
>> which is what tipped me off. Thanks Jeff!
>> OK, so far so good.
>> Now. Embedding...
>> I used the simplest example in the IPython manual pdf, in section
>> "3.2.4 Embedding IPython" on page 32-33.
>> I placed the following code into my app, in a button-click event handler.
>> def testIPyShell(self, sender, event):
>> from IPython.Shell import IPShellEmbed
>> args = ['-colors','NoColor','-noreadline','-classic','-x','Verbose']
>> ipshell = IPShellEmbed(args)
>> In the Project Properties page, I set "Command Line Arguments" to
>> -X:Frames and Interpreter Path to C:\Program Files
>> (x86)\IronPython 2.7\ipy.exe
>> (which is now 2.7b2) and check the "Debug Standard Library" box.
>> Hit F5, click the button and it works. The shell starts up. Main app
>> blocks on it, tho. Hmmm. Well, may be a way around that too.
>> But it starts up and runs. Type "%magic" or "?" and it prints out all
>> the doc, etc. Shell commands seem to work ok.
>> There is a minor issue in file iplib.py, line 646:
>> self.usage_min ="""\
>> where it continues a multi-line string. The trailing back irritates
>> the VS2010 Debugger to where it gets out of sync with the code.
>> I just took it out. If you're not running the debugger, you probably
>> won't ever notice it.
>> If you ARE running the VS2010 debugger, you will get all kinds of
>> stoppages, anywhere anything is raised. And it does that a lot.
>> Just ignore them. Hit the continue button.
>> And that's about it. Pretty cool little console.
>> All that having been said, of course, I think there may be an even
>> better option. Possibly.
>> Check this out:
>> Curt Hagenlocher posted this a couple of weeks ago. "Sho" is an
>> IronPython shell from MS Research Labs. Played with it some. It's
>> pretty cool. Very geared towards math/science/engineering apps.
>> The doc says it can be "embedded", but from what I have read (haven't
>> tried it yet), it looks like you can call into it and use it's code
>> and libraries of course, but I don't think the console will pop up.
>> Don't know for sure. Need to play with it and see. That's next.
>> (Also, downloaded SilverShell http://code.google.com/p/silvershell/
>> (written in IronPython and WPF) coupla weeks ago and got it running
>> under 2.7 - it's nice, but... seems to have some issues. I think I
>> like Sho better for simplicity and raw power. You might give 'em a
>> try and see which works better for you.)
>> That's all for now. Have fun with IPython. Holler if you have any
>> Users mailing list
>> Users at lists.ironpython.com
> Users mailing list
> Users at lists.ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Users