Archive for May 2009


VIM as Python IDE

May 24th, 2009 — 12:04 am

Finding the perfect IDE for Python isn’t an easy feat. There are a great many to chose from, but even though some of them offer really nifty features, I can’t help myself but feel attracted to VIM anyway. I feel that no IDE accomplishes the task of giving the comfort of complete power over the code – something is always missing out. This is why I always come back to using IDLE and VIM. Those two seem to be best companions when doing some quick and agile hacking – but when it comes to managing bigger and longer term projects, this combo needs some tweaking. But when it’s done, VIM will be a powerful IDE for Python – including code completion(with pydoc display), graphical debugging, task-management and a project view.

This is where we are going:

VIM as Python IDE

So, these are my thoughts on a VIM setup for coding (Python).

Modern GUI VIM implementations like GVIM or MacVIM give the user the opportunity to organize their open files in tabs. This might look convenient, but to me it is rather bad practice, because a second tab will not be in the in the same buffer scope as the first one which takes away from future interaction options between the two. Using MiniBufExplorer, however, gives the user tabs(not only in the GUI, but also in command line) and leaves the classic buffer interaction intact.

MiniBuf Explorer

Being able to neatly work on multiple files, the user still misses the potential his favourite IDE gives him in visualizing classes, functions and variables. Luckily there are quite a few plugins around to accomplish this task just as well. My favourite one would be TagList. TagList uses Exuberant Ctags for actually generating the tags(note: it really relies on this specific version of ctags – preinstalled implementations on UNIX systems won’t work).

TagList

A lot of coders have the habit of using TODO or FIXME statements in their code. Other IDEs often rely on having good third party project management software, but not VIM. There are great plugins like Tasklist reminding the programmer of those lines of code. Tasklist even implements custom lists – to me that’s an incredible productivity gain.

TaskList

In these times, the programmer knows his or her programming language more or less by interactively finding out what it can do. Therefore code completion(sometimes also called IntelliSense*ugh*) is a major feature. I have heard  many people saying that this is where VIM fails – but luckily they are plain wrong(; In V7, VIM introduced omni completion – given it is configured to recognize Python (if not, this feature is only a plugin away) Ctrl+x Ctrl+o opens a drop down dialog like any other IDE – even the whole Pydoc gets to be displayed in a split window.

Omni Completion

Probably the most wanted feature(besides code completion) is debugging graphically. VimPDB is a plugin that lets you do just that(. I acknowledge it is no complete substitution for a full fledged graphical debugger, but I honour the thought that having to rely on a debugger (often), is a hint of bad design.

VimPDB

From the eye-candy to the implementation. Don’t worry, it’s no sorcery.

First of all, make sure you have VIM version 7.x installed, compiled with Python support. To check for the second, enter :python print “hello, world” into VIM. If you see an error message like “E319: Sorry, the command is not available in this version”, then it’s time to get a new one. If you’re on a Mac, just install MacVIM(there’s also a binary for the console in /Applications/MacVim.app/Contents/MacOS/). If you’re on Windows, GVIM will suffice(for versions != 2.4 search for the right plugin). If you’re on any other machine, you will probably know how to compile your very own VIM with Python support.

Second, check if you have a plugin directory. In Unix it would typically be located in $HOME/.vim/plugin, in Windows in the Program Files directory. If it doesn’t exist, create it.

Now, let’s start with the MiniBufExplorer. Get it and copy it into your plugin directory. To start it automatically when needed and be able to use it with keyboard and mouse commands, append these lines in your vimrc configuration:

let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

For a project view, get TagList and Exuberant Ctags. To install Ctags, unpack it, go into the directory and do a compile/install via:

./configure && sudo make install

Ctags will then be installed in /usr/local/bin. When using a Windows machine, I recommend Cygwin with GCC and Make; it’ll work just fine. If you don’t want to tamper with your original ctags installation, you can propagate the location to VIM by appending the following line to vimrc:

let $Tlist_Ctags_Cmd='/usr/local/bin/ctags'

To install TagList, just drop it into VIMs plugin directory. You will now be able to use the project view by typing the command :TlistToggle.

Tasklist is a simple plugin, too. Copying it into the plugin directory will suffice. I like to have shortcuts and have added

map T :TaskList<CR>
map P :TlistToggle<CR>

to vimrc. Pressing T will then open the TaskList if there are any tasks to process. q quits the TaskList again.

VimPDB is a plugin, as well. Install as before and see the readme for documentation. If it doesn’t work out of the box, watch for the known issues.

To enable code(omni) completion, add this line to your vimrc:

autocmd FileType python set omnifunc=pythoncomplete#Complete

If it doesn’t work then, you’ll need this plugin.

My last two recommondations are setting these lines to comply to PEP 8(Pythons’ style guide) and to have decent eye candy:

set expandtab
set textwidth=79
set tabstop=8
set softtabstop=4
set shiftwidth=4
set autoindent
:syntax on

There are certainly a lot more flags to help productivity, but those will probably be more user specific.

Have fun coding Python while not being bound to a specific IDE, but having all the benefits of VIM bundled with a few helping hands. Enjoy, everyone.

If you liked this article, please feel free to re-tweet it and let others know.


    You should follow me on twitter here
twitter_preek

133 comments » | articles

Juno on Solaris 10

May 18th, 2009 — 02:23 pm

Juno is an incredibly lightweight webframework. Using Python as backend, it fullfills my very need for just about every small application I want to deploy against the web. It has no need for big runtimes on the server, no files to configure a great many files and most importantly: there’s no coding overhead – the programmer defines only the distinctively wanted features.
However, installing Juno on Solaris 10 isn’t quite as easy as described in Junos’ documentation. Solaris ships with Python 2.4, but Juno depends in Jinja2(a templating engine) which itself depends on Python 2.5+. Even installing Blastwave’s or Sunfreeware’s version won’t help. But that’s no biggie since compiling your own Python is incredibly easy.

  1. Get, compile and install Python (I have used version 2.5.4)
  2. Get, compile and install Setuptools

  3. Get, compile and install pysqlite
  4. easy_install install sqlalchemy
  5. easy_install jinja2
  6. Get, compile and install Juno

Enjoy.

Comment » | articles

Relentless resourcefulness

May 3rd, 2009 — 12:30 pm

What good is a weblog if one doesn’t keep track of the most important changes in life, at least? A great many things unfolded recently, so here we go.

First of all, it’s time to propagate that I’m writing using a new domain. The name gefechtsdienst.de was a remnant of old times and doesn’t really convey the feeling I want to share with the world. As of now I will be using dispatched.ch to publish applications and software snippets. To me the phrase dispatched channels the meaning of done and reliable; what has been dispatched doesn’t need a fix-up, it has been taken care of. Respectively my blog will be published on blog.dispatched.ch where I will keep writing and ranting(;

pre_pdict1

 

As a foretaste on what can be found on dispatched.ch in the upcoming future, I give you a screenshot of my current project to improve productivity on a Windows machine. I’m under the impression that nobody has ever written a decent translation toolfor it; not to mention the lack of anything for searching synonyms.

The web is no option for me; I can’t afford to maximize the strain to my hands each and every time I have to look something up. So I chose to write something from scratch. I will keep you posted on that one.

 
 

This brings me to matters of profession. Last week I had my first annual review which went really well, I might say. My work seems to be appreciated; resulting in a raise (2 weeks more vacation – which is good, because I need spare time a lot more than more money, nowadays) and the proposal as to whether I would like to work out even more own projects in the future. This includes going to (potential) customers, figuring out requirements, consult where applicable and finally implement those requirements in a new project. Likewise I’m getting the feeling that I really could go for quite some time in my current job. Even though I have always said that I won’t ever have to work with MS-Office or write accounting-software, it’s kinda nice to see your work really having a big impact on the efficiency of big companies and banks. In the current economical situation, I believe it is of utmost importance that cash-flow is guaranteed and that in an optimized speed. I might not work in a very fancy field with a young elite on a thriving web-project, but my work matters – not to the average user, but to the economy, which ultimately is needed for a happy life of each and every average user, isn’t it?

black1

green1

 

 

I’m even getting a little more business-proof along the way. This is what I have looked just a month ago and last week. Each picture was taken after a work marathon of over 12 hours in the bureau, so be kind in your assessment.

Well, I need new trousers and a nice belt. I’m thinking of brown Kapok.

 

Now it is time to post a picture of my workplace, at least. It was taken on my natural hour – when everyone else has left the building, already(; It features a left-over of my previous employer Sun Microsystems – my favourite keyboard, a Sun Type 7 in British English (really.. how can anyone think of coding using a Swiss layout*argh*). You can also see some decently stacked notes, my nice 24″ Dell screen and well.. a table, I guess(;

workplace

Then, I finally found a nice place to stay for good. Now I rent an apartment in Zurich City, featuring 2.5 rooms, 50m² and a nice balcony with a good view. In the first month I already invested the better part of 10k CHF(which has formerly been more than I had available for a year..), but it really is worth the struggle. I find myself no longer situated in a clumsy small, dark and unproductive room, located in a house full of wildly drinking and partying students, but in my very own realm – featuring green planes around it, a great view, a close nature conservancy, shopping opportunities  nearby and public transportation just around the corner. It’s a real dream come true. And due to the caring help of my dear grandparents I was able to really move in – I finally have a 2×1.6m bed, a couch(+ table) and a very nice workplace. Of course there’s every other piece of furniture, you would expect in an apartment, but those I consider real convenience. This is a picture on how my study looked like when I was still assembling it. Now, everything is finished and I probably will release some pictures when I’m content with all the accessories. But rest assured, it already looks a lot cleaner and nicer.

moving_in

 

But now to the utmost important change in my life – Katrin and I are back together again \(^_^)/

A good year ago we split up after sharing an apartment for a year and being a couple for over five. Who would have guessed that we could ever join again; from Stuttgart she moved to Weimar and I moved to Zurich – not only in this respect into opposite directions. But we found a way and now that she has moved again we’re only 40km apart geographically and can share a new and rejoicing quality of partnership. I love her and have been with her for the better part of my adult life – and I am very much looking forward to sharing the rest of it with her, as well. However, first we have to figure out our next anniversary and how many years we will be celebrating(;

On a stroll, April 2009

On a stroll, April 2009

Now why would I want to lead a life, relentlessly trying to improve it? Because in doing so, I find a great lot of joy, the time to work out, help my grandfather chop wood or go out and to the movies with Katrin without any further consideration – because I have created an environment in which I can find peace, love and happiness.

2 comments » | personal