Python wonderland

Last week I got to delve back into the world of Python at work to try and streamline part of our day-to-day working practices. I’ve never really got into TDD or MVP with Python, and we’ve been harping on about those techniques at work for some time now. So, I decided to get stuck in and try to do it all by the book. It ended up being rather more fun than I bargained for.

First up, since it’s what we’ve used on one or two other little projects, I stuck with Python’s built-in unittest framework, and pymox for mocking. Mocking and interfaces often feel like overkill in Python, but I stuck with it and ended up fairly happy with the results.

The test discovery (or lack of it) is a bit of a chore to set up, but I can put up with it. I briefly looked at nose, and that seems like an improvement, but I (we?) tend towards what’s avaiable in the standard Python libraries. It’s nice not to have too many external dependencies.

Since there’s no mocking framework in the standard library we didn’t really have a choice but to use an external library. I didn’t explore the alternatives, trusting that my colleagues had picked something decent. Pymox is roughly similar to Rhinomocks, but not quite as polished. I miss various little niceties like the difference between OnCall and ExpectCall. It’s all or nothing with pymox, you can’t just verify a subset of calls. It does the job, but just takes a little extra effort.

I’ve never done any gui stuff in Python, but this required a few simple buttons and text fields. After looking at all the options, I went with Tkinter just because it was already installed with ActiveState’s python on all our developent machines. It was easier than I expected, and gave reasonable-looking results on Windows at least, but it Looked a bit crummy on Linux.

Since the gui was done to the MVP pattern, it was easy to reimplement the front-end with a different toolkit. I was interested in giving PySide a twirl, and knocked up a second front-end which was even easier that Tkinter I’m surprised to say. It also looked a heck of a lot better in Linux. I’ll be giving this more attention some time soon because I really like it, being slightly used to Qt framework from previous side-tracks.

Packaging everything up in a distributable form wasn’t as straight-forward as I’d have liked, possibly due to the ActiveState python implementation on Windows. Using PyInstaller it was really easy to get the initial distro set up, but I couldn’t get the single executable version of the solution working. Something to do with not being able to find an msvc 9 dll. I think that’s a dependency introduced by the ActiveState python implementation on Windows. There was no time or point in hunting the problem down, so I just plumped for the single directory install instead.

I was surprised by the size of the installs though. The default one with Tkinter was around 8 megs, and the PySide one was closer to 25! Bear in mind that this is a tiny application that just talks to Jenkins over http.

The whole thing was developed in emacs and the tests I just ran from the command line. A bit old-school, but Eclipse drives me up the wall. Towards the end of the development I remembered that I wanted to try out PyCharm, a python IDE from JetBrains (the folk who do ReSharper). In short, it’s awesome. It’s almost like developing a statically typed version of python, as long as you document your function parameters and return types properly. The only downside is that it’s not free, but it’s good enough that I might just buy myself a copy anyway. Good enough that it’s making me think again about doing my never-gonna-happen project in Scala. Maybe it might actually happen if I go back to good old python with a decent IDE.

Last but not least, this was also a sneaky foray into using Git at work. It would really streamline our branching and merging policies. Keeping it short, I can see a lot of benefits, but I can see a lot of opportunity for us to shoot ourselves in the foot. Perhaps I’ll hold off on pushing this until we’ve got less to worry about at work. Some time next year maybe.

I’d quite like to open-source some or all of this, but I don’t think it’s generally useful yet, and I still have to get over puting my real email address out there for spam crawlers to find. A silly thing to worry about really, I know.

Overall, I had way too much fun. I’m not really sure why, but here are some theories. Perhaps it was the artistic freedom, not having to pair with someone (though it did get peer review at the end). Maybe it was just the break from the norm, some original work instead of refactoring. It could have been the (almost) instant gratification of a short project with fairly immediate pay-back.

This entry was posted in Uncategorized and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>