Sunday, September 2, 2012

Quick Fix: Upgrading Zope Interface so you can work on Twisted trunk post-12.2 release

Immediately after the recent 12.2 release, Twisted has upgraded its required version of Zope Interface.  Some platforms ship with a system-installed version of Zope Interface that is slightly too old for this change.  You may have noticed an unhelpful error message if you happened to svn up before learning about this change.

Upgrading system-installed Python packages without doing harm can be a challenge, so in this post we'll provide simple instructions for users who:
  • have a system-installed version of Zope Interface
  • are on a Unix-y platform, like Linux, BSD, or OS X (if you're on Windows, just upgrade to the latest on your system installation)
  • are not using a tool like virtualenv or Combinator to manage Zope Interface (if you are, you should already know what to do!)
  • don't want to upgrade anything system-wide, so as to avoid disturbing other users or software on their system
  • have easy_install already available in their environment.  (While Pip is generally better, it is pre-installed less often, and Pip doesn't seem to deal as well as easy_install with the case of parallel installation of user and system installed dependencies; it assumes you are using virtualenv for that. Update: as of the most recent release,  pip deals just fine with parallel user/system installation; so, if you've got pip installed, "pip install zope.interface==4.0.2" – possibly with a --user option if that's appropriate to your environment – will work just fine.  Thanks, Pip maintainers!)
This set of attributes describes many Linux and OS X developers who are likely to encounter this version skew issue, so off we go.

Since easy_install can't be coerced to do the right thing by command-line options, you'll need to give it a configuration file that it can read.  The easiest way to do this is to create a temporary directory, cd into it, and create a file called setup.cfg.  For Linux and BSD, setup.cfg looks like this:
For OS X, the file looks like this:
Once you've created that file, just  easy_install --upgrade zope.interface from that directory and you should be ready to start developing with Twisted again!  All the older versions of Twisted that I've tried still work with the newest Zope Interface so this shouldn't disturb your ability to test your code against older versions of Twisted as well, if you're managing it with something like Combinator or virtualenv.


anatoly techtonik said...

Glyph. I don't know what a Zope interface is. Can you list all use cases for it so that me or somebody else could rewrite it from scratch to remove the dependency?

glyph said...


I already wrote a lengthy blog post explaining why interfaces are great.

Specifically in Twisted's case, we originally had our own implementation of interfaces, in the twisted.python.components module. It was buggy, undocumented, didn't handle interesting corner cases, and was very slow at implementing things like adaptation, interface inheritance, and implementation inheritance, which can get surprisingly tricky with only a few levels of hierarchy. Zope Interface, by contrast, was thoroughly and thoughtfully designed, well documented, well tested, optimized in somewhat surprising ways, and just generally a huge improvement.

While we don't make heavy use of interfaces, it's important that what use we do make is correct in the face of interesting behavior from application programmers using Twisted. Despite the occasional complaint about the extra thing to download, depending on Zope Interface was one of the better decisions we've made in Twisted's history.

In most cases, the dependency will be resolved automatically by pip or easy_install or apt or yum anyway; this one minor edge case is just something that might arise for people working on Twisted itself, and updating by pulling from version control rather than installing a package.