Friday, May 30, 2008

Ouroboros

Circular dependencies will break your Python code!


Ouroboros

Given some module A that depends upon module B (ie, import B), and given a module B which depends upon module A, you'll get this rather cryptic error message:

ImportError: cannot import name A

This works at any remove, of course -- the circle could stretch through 1,000 modules, but once you forge that loop, you're toast.

The solution is to refactor your code to put routine from A needed by B into a separate module C that depends upon neither.

Wednesday, May 28, 2008

Leopard emacs is broken...

Which means that GNUplot is broken under Leopard, and with it, scipy.

Fortunately, there's a solution:


sudo mv /usr/bin/emacs-i386 /usr/bin/emacs-i386.backup
sudo /usr/libexec/dumpemacs -d
emacs --version
emacs


It's quite beyond me why the emacs shipping w/ Leopard is broken out of the box, but can be repaired via the dumpemacs command, but there it is.

Thursday, February 14, 2008

Redirecting from mod_python

The sort of thing I'm inclined to forget:


def handler(req):
req.headers_out['location'] = 'http://www.modpython.org/'
req.status = apache.HTTP_MOVED_TEMPORARILY
req.send_http_header()
return apache.OK


Care of the mod_python FAQ.

Monday, January 21, 2008

mod_python, Leopard, and the trouble w/ 64 bits

mod_python is broken under Leopard, at least on 64-bit capable systems.

Actually, this is only half true. Leopard ships w/ Apache 2, but more importantly, it ships w/ a 64-bit capable Apache 2. Because it's the 64-bit version that runs on capable systems, any modules linked by Apache need to be 64-bit capable.

Apache is 64-bit capable:

kieran@bali:~$ file /usr/sbin/httpd
/usr/sbin/httpd: Mach-O universal binary with 4 architectures
/usr/sbin/httpd (for architecture ppc7400): Mach-O executable ppc
/usr/sbin/httpd (for architecture ppc64): Mach-O 64-bit executable ppc64
/usr/sbin/httpd (for architecture i386): Mach-O executable i386
/usr/sbin/httpd (for architecture x86_64): Mach-O 64-bit executable x86_64

And mod_python, built by simply running ./configure and make, is 64-bit:

kieran@bali:~$ file /usr/libexec/apache2/mod_python.so
/usr/libexec/apache2/mod_python.so: Mach-O 64-bit bundle x86_64

So that much works. And basic mod_python functionality is intact. The problem comes when you try to compile python libraries that depend upon native C/C++ code. Neither command line options nor the CFLAGS environmental variable can force python distutils to build 64-bit friendly libraries.

I haven't figured out how to force distutils to cooperate yet, but in the meantime, rebuilding the entire software stack in fink creates a usable environment.

The first step is to simply ask for mod_python:

  1. stop apache: sudo service org.apache.httpd stop

  2. install the necessary packages: fink install libapache2-mod-python-py24

  3. accept the lengthy list of dependencies


Installing the PHP module wasn't so easy; I wound up building it by hand. First, make sure the Postgres include files are installed, assuming you need Postgres:

fink install postgresql82-dev

./configure --with-apxs2=/sw/bin/apxs2 --without-iconv --with-mysql=/sw/ --with-pgsql=/sw/

Monday, January 14, 2008

Magsafe Connector Disassembly

The chord nearest the Magsafe plug on a modern Apple laptop is under a good deal of mechanical stress, and mine finally gave out; the outer layer of wire looked like loose steel wool. So I decided to take the plug apart:






Notice that black bit on the PCB in the left-hand image? That's a chip, identified by the following text:

A3
2100
613A1

It most likely controls the switch between the orange "charging" LED indicator and the green "powered" LED. However, I wonder if this chip doesn't hold the answer to another mystery: why won't the Macbook battery charge off the Magsafe airline adapter?

For further information on the subject, I'd suggest Stuart Schmitt's guide to hacking the MagSafe cable for use w/ a standard DC transformer.

Tuesday, January 8, 2008

mod_python under Leopard

OS upgrades break my workaround for compiling mod_python under OSX.

This is a good guide for fixing mod_python under Leopard, but with a caveat: if you've upgraded your system from Tiger, the "missing symbol" problem might persist. Run otool -L /usr/libexec/apache2/mod_python.so -- if you see a reference to /Library/Frameworks/Python.framework/Versions/2.4/, that's your problem. I simply renamed /Library/Frameworks/Python.framework to /Library/Frameworks/_Python.framework and rebuilt.

Update: I take it all back; mod_python essentially doesn't work under Leopard, at least on a 64-bit capable system. See my Jan 21 post for more information.

Monday, December 17, 2007

Merry Christmas, San Francisco Style

Macy's on Union Square, Saturday, 15 December 2007. But a small portion of the March of Santas:



(About the photo: my apologies, but the camera on the Sidekick 3 is almost worthless. 1.3 megapixel, sure, but you've gotta drop the rez to VGA to smooth out the noise ... what a mess.)