For a long time I’ve wanted to try working with Bicycle Repair Man, the Python refactoring tool. Unfortunately, the fact that it had neither documentation nor integration with my favorite editor kept pushing it to the back burner.
About a month ago I was excited to come across a post from a guy named David Coffin who had created a BRM integration script for TextMate. I hooked it up per his instructions, and with a little fiddling I got it working. The first thing I tried was the Extract Method or Function command. I had code something like this (structurally, I mean):
def funfacts(string): l = len(string) a = string.count('a') u = string.upper() print "Length: %s Number of a's: %s Uppercase: %s" % (l, a, u)
I selected the three assignment lines, ran the “Extract Method or Function” command, and typed a name for the new function (
funfacts_helper) into the dialog. I hit return and my code changed to this:
def funfacts(string): l, a, u = funfacts_helper(string) print "Length: %s Number of a's: %s Uppercase: %s" % (l, a, u) def funfacts_helper(string): l = len(string) a = string.count('a') u = string.upper() return l, a, u
Cool. Now, people who have been using fancy refactoring IDEs for a long time may just laugh in their sleeves that I was impressed by this, but I was. This is great timing for me since I expect my copy of the Refactoring book to arrive any day.
biketextmate.py script supports five BRM commands: Rename, Find Definition, Extract Method or Function, Inline Local Variable, and Extract Local Variable.
I decided this thing needed to become a proper distributable TextMate bundle. (I actually have commit privileges in the bundle repository, not that you’d know it from my activity in the past year.) I made some minor changes to the
biketextmate.py script, mostly to improve handling of file paths with spaces. Boy, did it take me a stupidly long time to figure out where those errors were coming from.
svn co svn://open.e-scribe.com/python/misc/biketextmate
Update: I imported this into my new public Subversion repository and updated the previous command appropriately.
I don’t have contact info for David, but I’m posting a comment on his blog pointing here. So David, if you’re reading this, feel free to take my work and run with it, assuming you find it useful.
Craig commented :
I couldn’t get to the repository anymore but I downloaded the tarball. It has a slight conflict with the latest version of Bicycle Repair Man. You have to change all the brm.findDefintion() calls to brm.findDefinitionByCoordinates().
scott commented :
Have you still been using Bicycle Repair Man? Worth installing?