Total Eclipse Of The Python

Eclipse & Python, as the title suggests.  I’m not always elliptical in my references, you know.

I apologise if the title brings back memories of one of the several records with which Jim “I Produced Meatloaf, You Know” Steinman ruined Bonnie “Gravel Is For Gargling” Tyler’s 80s career, but if I have it in my head, I see no reason why it shouldn’t also end up in yours.  A problem shared is a problem halved.

Most of my development these days is done in a mixture of Java and Python, each language being used for the tasks for which it is best suited.  For a while there, I was doing Java in Eclipse 3.0 and Python in Boa Constructor, but even with 512Mb and not much else open, the laptop was beginning to groan.  Eclipse is approximating wonderful, but it eats memory like Americans eat corn-syrup-enhanced snacks.  Boa also likes to take up a fair amount of heap, so one of them had to go.  It had reached the point at which even partially exposing an Eclipse window after half an hour of ignoring it would slow everything down to a grind for a minute.  So I did some digging and discovered that Eclipse does support Python development.  Well, support is a relative term; it’s possible, if you’re willing to give up some things, or find workarounds.

First off, how to get Eclipse to handle Python at all.  There are at least five Eclipse Python plugins at some stage of development; after some testing (and not a few Eclipse crashes) I chose pydev.  The most obvious effect of installing this is that Eclipse recognises .py files and opens them in a Python-aware editor, with the Outline showing a nice list of methods imports and classes, including any if __name__ == ‘__main__’: block (no module-level variables shown, though).  The editor follows the Eclipse style of syntax colouring; might not be to your taste, but at least it’s more-or-less consistent between languages.

The most obvious lack is fully-Python-style code completion.  Many and better people than I have written on how damn difficult it is to implement this in Python anyway, so I suppose it’s a benefit to get anything.  Code completion’s off by default, and the PyDev Preferences tab for it contains dire warnings about how it works and what the drawbacks are.  In short, it “executes the code you write on the top level on the module” – I assume this means that it “imports” your code.  It looks like code completion’s then done with dir().  There are no tips for parameters to methods or functions, but you do at least get the docstring displayed.

Something else I missed pretty soon – a built-in Python shell.  I’ve impressed programmers in other languages before now by flipping between code-in-progress and an interactive shell to test out the statements I’m writing (avoids so many fence-post errors).  I’ve always found it especially good for regular expressions.  Also, of course, when you’re done coding, you have a bunch of handy test data and statements to hand to build the unit tests.  The quickest Eclipse workaround I’ve found is just to keep a Cygwin or Quasi window open running Python and to keep handy with the Windows console cut-and-paste.  I suppose SPE or PyCrust would do as well…

PyDev debugging has never worked for me, at all, though this is probably a blessing; meaning I tend to do much more test-driven development.  Since there are a bunch of other Python environments around if I really need to step through code, I haven’t bothered to dig into the depths of exactly why the PyDev Debug option never even appears for me.  Anyway, most of the Python code runs in Zope, and debugging Zope interactively is just… don’t go there.  Really.

A nice touch is that PyDev does it’s best to implement the Eclipse refactoring support, including renaming and extracting code to methods, though there are limitations on how far the renaming search appears to go.  Also, it sometimes seems to get slightly confused as to whether the source has changed or not.

Less obvious features: if you have the Subclipse plugin for Subversion integration with Eclipse, it’s now as easy to keep Python scripts and modules under control as it is Java (or any other file).  I especially like the ability to check in a set of Java and Python files all together when changes to both are needed to implement some system-wide change.  The Eclipse Local History (a sort of “persistent Undo”) also applies to Python scripts.

In short; it’s mature enough to do real serious work with, and the benefits of having all my code in one environment outweight the niggles.  After all, there’s no other Python IDE I’ve found that has everything I want in one package, let alone SubVersion integration.  In this world we are destined always to strive for perfection and never to find it.  I’ll settle for Eclipse & PyDev for the moment.

More info at http://www.python.org/moin/EclipsePythonIntegration

15 thoughts on “Total Eclipse Of The Python

  1. PyDev

    Hello,

    I am using the PyDev plugin on my small iBook. My Debugger works fine. I have absolute no Problems with it. It is a fine plugin. Enjoy 🙂

    • Re: PyDev

      Any hints on how to get the debugger working? I right-click on my hello-world program, pick Python=>Debug, get the ‘Modify attributes and launch’ dialog box, press Debug, and then it executes my program, but I can’t figure out how to set breakpoints or single step. Setting a breakpoint with right-click in the source doesn’t appear to work.

  2. Something else I missed pretty soon – a built-in Python shell

    I just set up the Python interpreter as an Eclipse “External Tool”. Would this not suffice?

    • Re: Something else I missed pretty soon – a built-in Python shell

      Might do… but that’s a lot of clicking to get to it vs. an open Cygwin window…
      b

  3. Eric3? anyone?

    Hi there,

    I’m using Eclipse (w/o many plugins tho) for Java and Eric3 for Python. Eric3 is relatively lightweight and so even when my 256MB laptop grinds to halt when I switch between IDE’s, it surely doesn’t so for a full minute.

    Then again, I don’t use Cygwin on Win32 but SuSe 9.1 😉

    Eric3 has support for Subversion, a built-in interactive interpreter (can’t get ipython to work with it tho) and comes with BiCycle Repair Man for refactoring.

    Although nothing beats Eclipse for real software development (with the proper plug-ins, that is) I fell in love with Eric3 as soon as I discovered it.

    Of course, I can understand why you want to keep your Java/Jython development in one IDE and then there’s no choice but to ‘release the monster’..

    cheers,

    Remco

    • Re: Eric3? anyone?

      Ah, if I could run Linux on this laptop, I would. Unfortunately, there are just too many incompatibilities with the stuff I need to use day-to-day. But that’s a whole ‘nother story.
      I’ve tried many IDEs for Python, but not Eric3 – care to provide a URL? I doubt I’d switch now, though, being able to combine the two languages in the same Eclipse projects is proving more and more to be a Good Thing, which in itself makes up for the shortfalls of PyDev.

  4. Tabs

    The thing I am missing in pydev is proper diagnosing of mixed indentation, or indentation in a source file which does not match its own indentation settings. Getting these mixed up is a very subtle way of messing up a nice py-file.
    The best support I’ve seen for this thusfar has been in PythonWin which I do not think is an option for my Linux pc.

    Keeping everything in the same IDE has huge advantages. It sure helps me keep everything focused and in one place.
    I wrote my Bachelor’s report using a LaTeX plugin for Eclipse. And I do all my CVS/SVN repository browsing in Eclipse. I can’t be bothered to try out different UI’s which usually are severely lacking.
    Eclipse works just fine. And having at least a Gig of RAM does help.

    Subclipse is still direly lacking a proper Team Synchronize feature to make it a viable substitute for the builtin Eclipse CVS-support. I wish Eclipse would offer the same support for Subversion as they do for CVS.

    • Re: Tabs

      Absolutely agree about mixed indentation – it can be a severe pain. However, if you know what space/tab level it was edited at, you can often fix it with some careful python scripting of your own (scripts hacking scripts? Neo would be proud). Or the good ole Unix command “expand”, of course.

      Personally, I don’t miss the Team Synchronize, but then the team usually just consists of, er, me.

      • Re: Tabs

        Neither do I miss Team Synchronize but for the shop where I work its absence is a showstopper for migration to SVN.

        And if that is the case with us it probably is the same for a significant amount of other sites. So lack of that feature is blocking more widespread SVN adoption (and consequently a better world).

    • Re: Interactively debugging Zope is great fun

      I do, and I’ve tried ’em, I just don’t have the time to become an expert on Zope internals. The more I’ve dug down into watching how objects are instantiated and removed in Zope, the more I appreciate the tremendous complexity of the system. Note that I don’t call it “overcomplexity”; I don’t believe that to be the case, given the requirements I understand it was built to meet. However, it’s sufficiently complex that I’ve retreated from having any Zope Products of our own, or even subclassing existing ones. Instead, we use ZPT as a presentation layer, keep business logic in ExternalMethods (or PythonScripts), keep assets like images in the ZODB and treat Zope as a Python web server engine. In which role it runs very well.
      But that’s not really a response to the links about debugging; what I’m getting at is that my aim is now to use Zope in a manner that means I don’t need to grok the internals. Our experience has been that you can venture into the depths of Zope only if you accept that it can be a tremendous timesink. I’d personally rather enjoy that, but I can’t justify it in a business sense.

  5. Using the Python interactive shell within Eclipse

    Search for “Using the Python interactive shell within Eclipse” in the article “Python development with Eclipse and Ant”.

    Enjoy!

Leave a reply to bjlast Cancel reply