Farm Development

Thoughts on TextMate

back to all thoughts

Python on TextMate demo (Chicago area)

If you are in or around the Chicago area, I will be demo-ing some techniques for coding Python in TextMate, an editor for Mac OS X. It's part of the Snakes On Apples themed Chipy (Chicago Python Users) meeting. It's at 7pm, Thursday August 9th; click the link for more info and directions.

I'll try to cover the basics but then also some of the more advanced stuff like creating custom Bundles to automate tasks (Commands / Snippets/ Macros). And if all goes well, I'll be able to show off my somewhat-working, revisted version of running an interactive doctest session directly in the docstring of a python file. I started working on this a while back but had set it aside.

Live doctest in TextMate (IPython + Twisted?)

I use TextMate for all python dev and I've had this idea to make typing doctests yield live results. In other words, when you are editing a module, if you were in a doctest you would type a line of code and the next line of your module would contain the result.

Just imagine typing and getting back...

This is how you use the class::

    >>> foo = Barbaz()
    >>> if foo.babulated:
    ...     foo.unbabulate()
    ... 
    'foo is now unbabulated'
    >>>

...I dunno about you, but I think that'd be slick!

The implementation is pretty simple with IPython :

from IPython.iplib import InteractiveShell
s = InteractiveShell('shell', user_global_ns=globals())
s.push('class foo(object):')
s.push('    pass')
s.push('')
s.push('foo')
# <class '__main__.foo'>

...huzzah. In TextMate, you can execute a script on the <return> key and the script would get $TM_CURRENT_LINE, full text of the line you're on. However, the current framework would execute the script once each time you pressed return so there is a problem with shared memory (no record of the previous lines you fed into it).

This is the part I'm still trying to figure out. I could fork another process and make some kind of interface (REST, pyro?) for feeding it new lines. The shared namespaces could be hashed per file, using $TM_FILENAME, and could simply use timeouts to do cleanup. It would need some security—maybe a block of all non-local IPs + some kind of permission check per user, but this is all I can think of. Anyone know of a better way? Anyone interested in this kind of thing? I am getting a heavy feeling that I need to learn Twisted! Can anyone point me in a good direction for how to do this in Twisted?

Recent Projects

  • JSTestNet

    Like botnet but for JS tests in CI.

  • Nose Nicedots

    Nose plugin that prints nicer dots.

  • Fudge

    Mock objects for testing.

  • Fixture

    Loading and referencing test data.

  • NoseJS

    Nose plugin that runs JavaScript tests for a Python project.

  • Wikir

    converts reST to various Wiki formats.