a blog by Marius Gedminas

Easy easy_install on Ubuntu Gutsy

I want to be able to install small and simple Python packages from Cheeseshop by typing 'easy_install packagename'. This does not work out of the box on Ubuntu Gutsy (even after installing python-setuptools): easy_install tries to install stuff into /usr, which (a) requires root permissions and (b) is just Not Done on Linux, where /usr belongs to the distribution's package manager1.

1 /usr/local is for extra stuff. I consider it a bug in setuptools that it prefers /usr over /usr/local.

So, here's a quick HOWTO distilled from the easy_install documentation and improved by a suggestion from Audrius Kažukauskas to use aliases instead of ~/.pydistutils.conf:

  1. sudo apt-get install python-setuptools
  2. mkdir ~/bin ~/py-lib
  3. Add the following near the top of your ~/.bashrc:
    export PYTHONPATH=~/py-lib
    alias easy_install="easy_install -s ~/bin -d ~/py-lib"
    
  4. Make sure your ~/.bash_profile contains
    PATH=~/bin:"${PATH}"
    . ~/.bashrc
    
  5. Remove ~/.pydistutils.cfg if you created one by following an earlier version of this HOWTO

This is not the recommended method of installation, but it is certainly the simplest one (from my point of view), and appears to work with the sort of simple pure-Python packages that I installed. I guess I'll stick with it until it breaks.

Update: the custom ~/.pydistutils.cfg file breaks virtualenv.

Update 2: Audrius Kažukauskas suggested using an alias instead of the custom ~/.pydistutils.cfg file.

Update 3: I should've mentioned before that you need to apt-get install python-setuptools.

Simplifying dependency graphs with graphviz

Remember the package dependency graph of z3c.formdemo produced by tl.eggdeps?

z3c.formdemo dependency graph (small version)
the insane graph, scaled down from 14153x2729 to 480x93

If you filter the dot file through tred from the graphviz suite of tools, it will remove redundant dependencies (that are already implied by transitivity) and produce something actually useful:

z3c.formdemo dependency graph filtered by tred (small version)
the useful graph, scaled down from 2695 x 2394 to 480x426

Foliage sprint day 2

Stephan Richter convinced me to try the ZCML optimization task. Zope 3 parses and interprets hundreds of little ZCML configuration files on startup. The idea was that if we can cache pre-parsed configuration on disk, we could speed up Zope 3 startup by 30–50%.

I originally tried this approach back in 2004 but couldn't get it to work. Today, thanks to Stephan Richter, who took over the most boring and difficult parts (making view directives pickleable), we got to a point where Zope 3 works after loading the configuration pickle instead of parsing ZCMLs (and starts up in 2 seconds instead of 3).

The code is still at a prototype/proof-of-concept level, full of ugly hacks. The tests are also not very happy (68 failures, 115 errors out of 6955 tests). The patch describes the changes in greater detail.

We also had a nice dinner in a Japanese all-you-can-eat buffet called Minado.

Foliage sprint day 1

One of the reasons I wanted to come to the Foliage sprint was to get acquainted with the brave new world of Zope 3 eggs. For this reason I chose to work on package dependency simplification.

I spent a couple of hours reading setuptools documentation, easy_install and zc.buildout source code, trying to figure out the right way to extract dependency information from a set of eggs. Then philiKON mentioned tl.eggdeps to me. Yay!

Running it on z3c.formdemo produced a huge and unreadable graph. The original was 14153x2729 pixels, here's how it looks when zoomed out:

z3c.formdemo dependency graph (small version)

The text version of the dependency tree was better, but not too convenient either. I got the idea of an interactive dependency tree viewer so that I could expand only those parts I'm interested in and ignore the others. That's what I worked on for the rest of the day:

Gtk+ egg dependency viewer

You can easy_install gtkeggdeps and inspect the dependencies of all your installed packages.