Install wxPython in buildout

While completing setup of this blog with WordPress, I’ve also been working on another task: adding wxPython dependency to a pythonic project of mine. The deployment of this project is done through buildout, a nice piece of software that handles a sandboxed environment for python projects.

You can find download and install instructions to start a buildout barebone here, however I will do a small recap:

First, check that your python installation has setuptools installed (platform-specific install instructions here).

Then run the following commands to create your new project and fetch bootstrapping script:

$ mkdir projectdir
$ cd projectdir
$ wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
$ mkdir downloads # this is needed, as buildout won't create it by itself.

Next step is writing buildout.cfg, an ini-style configuration file that specifies the setup for your deployment. The generic section is named “buildout” and its “parts” attribute refers to other sections that must be evaluated. I’ve created two parts: an example named “myproject”, which downloads, builds and installs a couple of fake eggs with wxPython in PYTHONPATH and a “wxPython” part, which downloads, builds and installs wxPython inside “parts” directory.

Each part is evaluated using a recipe, which is a plugin that is dynamically download from eggs repository or any other repository you pass through a find-links attribute. For my purposes I’ve employed two recipes from minitage project, a software deployment project developed by a nice french dude called kiorky (you can chat with him and obtain support at #minitage on irc.freenode.net).

[buildout]
download-cache = downloads
parts =
    wxPython
    myproject

[myproject]
recipe = minitage.recipe.egg
eggs =
    myegg
    myotheregg
extra_paths = ${wxPython:location}/lib/python

[wxPython]
recipe = minitage.recipe.cmmi
url = http://downloads.sourceforge.net/wxpython/wxPython-src-2.8.10.1.tar.bz2
post-make-hook = ${buildout:directory}/hooks.py:wxpython_post_make_hook
configure-options =
    --enable-debug --enable-debug_gdb # replace with --enable-optimize in production code
    --enable-display
    --enable-geometry
    --enable-graphics_ctx
    --enable-mediactrl
    --enable-sound
    --enable-unicode
    --with-libjpeg=builtin
    --with-libpng=builtin
    --with-libtiff=builtin
    --with-opengl
    --with-sdl
    --with-zlib=builtin
# Platform-dependent options, add as needed. Platform names are from sys.platform.lower().
configure-options-darwin = --with-mac --enable-monolithic
configure-options-linux2 = --with-gtk2

Configure-make-make-install recipe, namely minitage.recipe.cmmi, has a series of special options called “hooks” that allow extending the building process with non-standard actions through python code. I’ve added a call to wxpython_post_make_hook in hooks.py to deal with special post-install code:

import os
import sys
import subprocess

def wxpython_post_make_hook(o, b):
    return subprocess.call([sys.executable, 'setup.py',
        'WX_CONFIG=%s' % os.path.join(o['location'], 'bin', 'wx-config'),
        'BUILD_GIZMOS=0', 'BUILD_STC=0',
        'install', '--home=%s' % o['location'],
        ], cwd=os.path.join(o['compile-directory'], 'wxPython'))

Please note that I’ve disabled gizmos and stc support from wxPython, because I don’t need them and ¬†they would require additional building in contrib.

Finally, launch the bootstrapping code:

$ python2.6 ./bootstrap.py

Of course, if you have a different version of python installed, adjust the command accordingly.

Now buildout is ready to be executed with:

$ ./bin/buildout

That’s all folks!

This entry was posted in Coding, How-tos and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. 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>