[Distutils] compiling psycopg2 with zc.recipe.egg: allowing custom build_ext options?

Kevin Teague kevin at bud.ca
Thu Oct 1 00:07:11 CEST 2009


Regarding Chris recent thread on doing some hair pulling while getting
psycopg2 to install, I recently added this distribution to a buildout
with the following configuration:

[versions]
pscopg2 = 2.0.8

[buildout]
parts = app postgresql init-pgsql pgsql-symlinks psycopg2
find-links = http://initd.org/pub/software/psycopg/PSYCOPG-2-0/
versions = versions

# app is a Grok-based application that requires pscopg2
[app]
recipe = zc.recipe.egg
eggs = ${psycopg2:egg}
       gsc.docsdb
       z3c.evalexception>=2.0
       Paste
       PasteScript
       PasteDeploy
interpreter = python-console

# PostgreSQL parts

[psycopg2]
recipe = zc.recipe.egg:custom
egg = psycopg2
include-dirs = ${postgresql:location}/include
library-dirs = ${postgresql:location}/lib

[postgresql]
recipe = zc.recipe.cmmi
url = http://wwwmaster.postgresql.org/redir/198/h/source/v8.3.7/postgresql-8.3.7.tar.gz
extra_options =
  --with-readline

[init-pgsql]
recipe = iw.recipe.cmd
on_install = true
on_update = false
cmds =
  ${postgresql:location}/bin/initdb -D ${postgresql:location}/var/data
-E UNICODE

[pgsql-symlinks]
recipe = cns.recipe.symlink
symlink_target = ${buildout:directory}/bin
symlink_base = ${postgresql:location}/bin
symlink =
  clusterdb
  createdb
  createlang
  createuser
  dropdb
  droplang
  dropuser
  ecpg
  initdb
  ipcclean
  pg_config
  pg_controldata
  pg_ctl
  pg_dump
  pg_dumpall
  pg_resetxlog
  pg_restore
  postgres
  postmaster
  psql
  reindexdb
  vacuumdb

This builds a complete PostgreSQL install inside the project
directory. Of course, if you've already got a preferred postgres
install, you can simplify this quite a bit and just point the include-
dirs and library-dirs to that location.

I did find that I had to pin psycopg2 down to 2.0.8, since it didn't
seem to work with 2.0.10. But looking a bit further into this issue,
the preferred way to build psycopg2 is to supply the full path to
pg_config as a build_ext.

However, zc.recipe.egg:custom only supports a fixed list of build_ext
options. Is this a feature or a bug? e.g. Is there any reason why it
wouldn't be possible to support arbitrary build_ext options with this
recipe? Or is there another egg-building recipe out there which
supports this?

By patching a local copy of zc.recipe.egg to allow the pg_config
build_ext option, I was able to use this part to compile psycopg2:

[psycopg2]
recipe = zc.recipe.egg:custom
egg = psycopg2
pg_config = ${buildout:bin-directory}/pg_config

Which worked fine for the latest release, 2.0.10, of psycopg2.

(also, as a bonus 'Arg!', note that it's necessary to supply a custom
find-links URL to buildout, since the PyPI page for psycopg2 has bogus
download links)



More information about the Distutils-SIG mailing list