views:

96

answers:

4

I have been developing a project in python for the last six months, and love the language. But I have yet to find an IDE or text editor that could provide some extra functionality for me. I currently have syntax highlighting which is one of the easiest things to get, but not much more. I am dreaming of having my IDE jump to the line in my code that caused the crash instead of reading the line number from the backtrace and manually locating it in my text editor. I have been looking for something that could do this under my development constraints, but no success. My constraints are the following:

  • The python code being developed rests on a remote machine, equipped with enough RAM and CPUs to run the code. That machine has no screen or keyboard.
  • I code from my laptop, a macbook pro running OS X which is not meant to execute the code.
  • The remote machine is running Fedora 12 and provides SSH connectivity with root access.
  • My connection isn't good enough at home to run an X11 IDE on the distant machine and have the interface displayed on my machine.

What I have been doing up to now is to log-in to the remote machine via SSH using the excellent CyberDuck client. This enables me to open a text file residing on the remote machine inside any of my local usual text editors like TextMate or TextWrangler and have changes uploaded automatically every time the file is saved. This really gives you the felling you are editing the distant file in your usual cocoa interface.

Then to execute the python code, I open a second SSH connection, this time using a terminal into which I would type:

$ ssh user@dns
$ ipython -pylab
$ execfile("/projectdir/code.py")

Finaly, I read the backtrace and go back to my local text editor to find the correct line number. There must be a better way ! Any ideas ?

A: 

You should keep your eye on PyCharm - it isn't production ready yet, but it has some real potential to be a great IDE. I've been using it for about 7 months now - you can renew the 45 day free trial as long as you keep your build current. I believe that remote debugging is a feature that the production version will support.

Matthew J Morrison
I had installed PyCharm when searching for a better IDE, but, as you say, remote debugging is not yet included. I will keep my eye on it of course.
xApple
+1  A: 

Hi,

here is a good list of Python-Editors and there's also a poll here at StackOverflow.

In my opinion WingIDE (there's a free version) is very feature-rich, good and easy and supports Remote-Debugging (only in the commercial version). Also Eclipse PyDev-Plugin, which is fully free, is worth looking into it and seems to support Remote-Debugging.

Joschua
WingIDE might be up to the task... They do however state that "Since remote debugging is fairly complicated to configure, we currently recommend using remote display of the IDE via X Windows". Also, this is just for debugging, it won't let you edit the files on the remote machine and run them directly. It's up to you to transfer and synchronize all your code between both machines at every run.
xApple
A: 

It's been years since I used it, but the commercial version of Komodo includes a remote debugger, and is generally a very competent package for Python programming.

Alternatively, you might try a standalone remote debugger: WinPdb - which, despite the name, works on Mac and Linux - is very good.

Daniel Roseman
Unfortunately forking out 300USD is not an option for me at the moment.
xApple
Yes, my experience of it dates from when they allowed you a complete version for personal non-commercial use.
Daniel Roseman
I have used WinPdp and understand how you can attach it to a process. However this doesn't provide a solution for remotely editing files and running them automatically.
xApple
+2  A: 

You may or may not like this suggestion, but I would use vim, setting makeprg and errorformat appropriately. This way you can ssh in as normal, edit files directly on the remote machine, and compile/error fix using quickfix-errorlist. It will only cost you the time to set makeprg and errorformat correctly. If you do a little digging the info is out there.

EDIT

  1. ssh [email protected]
  2. Put the lines at the bottom of this answer in ~/.vimrc
  3. vim somemodule.py
  4. Type ":make somemodule.py"
  5. Type ":cw" which may stand for c as in the language, window
  6. vim will popup a window [Quickfix List]
  7. Cursor over an error in the [Quickfix List]
  8. Press enter
  9. vim changes your cursor to the window above and places it on the error
  10. Fix the error using your vim skills, ":h" for help and tutorials
  11. Ctrl+w, j will move the cursor down a window, back to your quickfix list
  12. Ctrl+w, k will move the cursor up a window
  13. Repeat steps 7-12 as necessary
  14. ":make somemodule.py" to make sure you fixed everything
  15. Welcome yourself to the darkside, vim rules.

~/.vimrc settings:

"python makeprg settings

setlocal makeprg=python\ %

setlocal errorformat=
        \%A\ \ File\ \"%f\"\\\,\ line\ %l\\\,%m,
        \%C\ \ \ \ %.%#,
        \%+Z%.%#Error\:\ %.%#,
        \%A\ \ File\ \"%f\"\\\,\ line\ %l,
        \%+C\ \ %.%#,
        \%-C%p^,
        \%Z%m,
        \%-G%.%#

Setting makeprg tells vim that you're "compiler" is python. Setting the errorformat tells vim how to parse the output of your "compiler" so you can jump to error lines. Look around on the internet, there are plenty of vimrc suggestions for programming in python. There are makeprg/errorformat settings for Xcode/Visual C++/Perl/etc as well which really makes vim a win-win situation if you program in different languages. There's also other fancy stuff like autoindent, code completion and syntax highlighting. Enjoy

Note: These settings were taken almost verbatim from here.

manifest
I thought about using a terminal text editor like emacs or vim. I might be ready to go for the reduced interface. But will this solution make me jump to correct line when execution crashes ?
xApple
Since you've shown interest I've edited my answer
manifest
Since "compiling" and running a python program are essentially the same from a vim point of view it will take you to the correct line when the execution crashes
manifest