Cog 2.2

Thursday 25 June 2009This is 14 years old. Be careful.

I’ve updated my code generation tool, Cog. It’s now supported on Jython 2.5, and I’ve removed the handyxml module it used to ship with, since most Cog users have no need of it. There’s no functional changes.

Cog does one thing well: find snippets of Python code in text files, and run them, capturing the output and splicing it into the file. It can be used for all sorts of code generation and preprocessing tasks.

The irony of Cog is that I wrote it back when I worked in C++ and needed to generate code. Now that I work in Python, I don’t need it, or so I thought. But this winter when I was writing my Whirlwind Excursion through Python C Extensions, I wanted a way to create the slides and the web page from a single source, and also not have to copy and paste sample code between runnable files and the text source. Cog would have been a great way to do this. For example, Paver uses Cog for just this sort of job.

But it didn’t even occur to me to reach for Cog, and I ended up hacking something together. So I have to try to remember Cog in the future.

I updated Cog because I got two requests in one week to update it to keep it working on newer Python implementations. I’m going to start porting projects to Python 3.0, and Cog may be the first, since it is relatively small and simple.


Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.