Tuesday, January 15, 2008

Many versions of one Python package

I had to spend some time today working out how to use pkg_resources correctly. I've got multiple versions of SQLAlchemy, and I expected that this code:
import pkg_resources
would simply active the correct package and everything would just work.

Not so.

In order to use multiple versions of a package, you must install it with the --multi-version option. Eg, these commands:
easy_install --multi-version SQLAlchemy==0.3.11
easy_install --multi-version SQLAlchemy==0.4.2
will let you use pkg_resources to activate different versions of the SQLAlchemy package. Without the --multi-version argument, pkg_resources.require will only perform a dependency check, rather than check and activate the required version.

Saturday, January 12, 2008

Deeply Nested Resources in Pylons

I've finally got around to working out how to achieve deeply nested resources in Pylons and Routes.

Say you want a URL like this:


where 'some_book', 'some_chapter', 'some_page' are member names you want to fetch out of the 'book', 'chapters' and 'pages' collections.

Using routes, you cannot achieve this using the 'parent_resource' option only. You need something extra. The config/routes.py file will need to have these entries:
map.resource('book', 'books')
map.resource('chapter', 'chapters', parent_resource=dict(member_name='book', collection_name='books'))
map.resource('page', 'pages',
path_prefix = '/books/:book_id/chapters/:chapter_id',
name_prefix = 'page_'
The route_dict dictionary still has all the information you need. I haven't tried this beyond three resources.

Tuesday, January 01, 2008

Fireworks from the Balcony.

Fireworks from the Balcony.
Originally uploaded by simonwittber
NYE 2008 Fireworks in Perth, Western Australia. Taken from my balcony.

Popular Posts