Thursday, March 20, 2008

Interactive console in Pydev


Last week I started working on an interactive console and bundling it into pydev. Hopefully it'll be finished soon (probably within the next 1-2 weeks).

The main structure is already in place... code-completion, context info on hover, history (up/down arrow), colors for stdout/err/prompt/user input, auto-indent, python/jython support, it's all there already... (but I want to add an extra layer of polishment before releasing it).

Under the hood, it's almost like a whole new editor covering the console, while communicating through sockets with a python shell (but it feels a lot like a regular editor, in the sense that the same options that are used in the editor for indent, code completion, etc. are also available from the console -- with the exception that you can actually only edit the active line).

Also, this time I was able to get some code that had an initial draft of a console from dltk (which was pretty nice), but I had to do some (not so minor) changes to be able to add it to pydev, although the basic structure still has the same idea (the result can be seen at org.python.pydev/src_dltk_console).

Well, to sum it up... this is a long-awaited feature, and the plans are for surpassing all expectations on that :)

21 comments:

Anonymous said...

Sweet...

Unknown said...

How will this compare to iPython? I've often wished I could get iPython directly into pydev and set it up so that when I run %edit it just opens a new file right there in pydev for me, saving it runs it in the iPython console. Would be great to setup an initial setup in the project definition so that when I go to work on my Django project, the shell is setup with the paths and such I need for that. Then if I go to another project, the shell would update as well.

manuel moe g said...

deuce868's comment about iPython; Seconded!

Justin Marrington said...

You sir, are a gentleman and a scholar. I just installed and tested PyDev for a uni project, and was thinking 'hey, this is absolutely fantastic, but I wish I didn't have to have IDLE running as well for on-the-fly experimentation'

Bernd said...

Failed to read servers response: Connection refused>>> import sys
Failed to read servers response: Connection refused>>> print '%s %s' % (sys.executable or sys.platform, sys.version)
Failed to read servers response: Connection refused>>>

after that the console works but nothing was imported. A couple of newlines at the beginning of the initial import in the preferences seem to help, but the jython console doesn't work at all:

Failed to read servers response: Connection refused>>> import sys
Failed to read servers response: Connection refused>>> print '%s %s' % (sys.executable or sys.platform, sys.version)
Failed to read servers response: Connection refused>>>
Console already exited with value: 255 while waiting for an answer.
>>> print "foo"
Console already exited with value: 255 while waiting for an answer.
>>>

Fabio Zadrozny said...

This seems like you have something blocking communication with the shell... do you have some firewall enabled?

slh said...

Can someone tell me how to install this test version? I would love to try it out.

Fabio Zadrozny said...

It has just been released: http://pydev.blogspot.com/2008/04/pydev-1315-released-new-interactive.html

Cheers,

Fabio

Bernd said...

"This seems like you have something blocking communication with the shell... do you have some firewall enabled?"

No, I have no firewall. I suspect some kind of race condition (it behaves like random and it has something to do with time), sometimes it works with only 2 empty lines at the beginning, sometimes not and today it worked one out of two times without an empty line at the beginning. After the prompt is there the console (CPython) works perfectly, but the Jython console won't work at all.

I have Kubuntu 7.10, Eclipse 3.3.2, PyDev 1.3.15, PyDev-Extensions deactivated because of another indeterministic problem, Hardware is an old ThinkPad-T40 (Pentium-M 1500MHz, 500MB RAM).

Fabio Zadrozny said...

Can you please report that as a bug in sf?

Anonymous said...

cannot get interactive console during debug, e.g, to check functions and variables, etc. The usual stuff a debugger has.

Yaakov

Bruce Edge said...

I have the following error too:
>>> import sys; print '%s %s' % (sys.executable or sys.platform, sys.version)
Failed to read servers response: Connection refused>>>

I'm using a remote python debugger with my target. Is there any dependency on whether the target env is remote or local?

My host is ubunto 8.04 with eclipse 3.4 and pydev 1.3.18

Is there some diagnostic or tracing that I can turn on to help debug this?

Fabio Zadrozny said...

That specific bug should be already fixed in the latest version in the cvs.

Cheers,

Fabio

Gökhan Sever said...

Is there any plans for IPython integration?

Fabio Zadrozny said...

There are no plans for the iPython integration... Is there some specific feature of iPython that you're missing from the interactive console?

Unknown said...

The Pydev console is great and in my opinion a must-have for development so many thanks for the good work put into this. I can't make it work in debug mode however - any plans to add this in?

Fabio Zadrozny said...

There are currently no plans to add that support to the debugger. Note that pydev extensions has a simple console already (you can type statements to be evaluated, but it has no code-completion: http://fabioz.com/pydev/manual_adv_debug_console.html )

Unknown said...

ok thanks, that seems to do the job. Will try it out.
Soren

Oz said...

Nice idea, but not needed anymore.
The PyDev installation provides a Python console.
From Console view, open a new console (icon upper right corner) and select Python console.
Bingo - you have a python command line.

MZ said...

PyDev is great - thank you very much for the huge effort.

So far I am having to use both PyDev and Spyder, however. PyDev for the debugging and because I like and use Eclipse for Java.

Spyder because the interactive environment is better. Most of this is down to two simple issues. In Sypder you can select a block of code in the editor, and send it to the integrated ipython browser by pressing F5 *even if indented* (i.e. automatically remove the top layer of indentation).

PyDev won't remove the indenting, so generates a lot of IndentationError exceptions, which makes it unusable. (Also Ctrl-Alt-Enter is much more painful than F5 if you use it a lot, and F9 in Spyder to simply rerun the current program in the console is much more convenient than the mouse and window manipulation in pydev to close and rerun a previous attampt. Of course this is the same for Java on eclipse, but it is a much less frequent operation than in Python).

I feel bad appearing to criticise a fantastic and powerful and free tool (debugging is much better than Spyder, and the single IDE for all my code and version control is fatastic)- but if you could address these issues it would be even better.

Fabio Zadrozny said...

Please enter those as feature requests ( http://sourceforge.net/tracker/?group_id=85796&atid=577332 )

Thanks,

Fabio