Buildout -- Software for automating application assembly

Comment 2 for bug 410528

Wichert Akkerman (wichert) wrote :

I noticed the same thing on a clean Ubuntu 10.4 install today. This appears to be caused by Ubuntu installing pkg_resources but not the rest of setuptools, and all without any egg info.

A partial improvement apppears to be to try to import both pkg_resources and setuptools instead of just pkg_resources. That at least gets things to the point where zc.buildout downloads setuptools. It still fails later on though:

Downloading http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
Traceback (most recent call last):
  File "bootstrap.py", line 116, in <module>
    ws.find(pkg_resources.Requirement.parse(requirement)).location
AttributeError: 'NoneType' object has no attribute 'location'

Looking at it further the correct approach might be something like:

* if pkg_resources fails to import download & install setuptools
* if setuptools fails to import download & install setuptools
* if pkg_resources imports correctly but setuptools fails to import download & install setuptools and reload pkg_resources

I used the patch below as a quick test and that got things working for me, so it's probably a good start.

Index: bootstrap.py
===================================================================
--- bootstrap.py (revision 13408)
+++ bootstrap.py (working copy)
@@ -56,6 +56,7 @@
 to_reload = False
 try:
     import pkg_resources
+ import setuptools
     if not hasattr(pkg_resources, '_distribute'):
         to_reload = True
         raise ImportError
@@ -72,8 +73,10 @@

     if to_reload:
         reload(pkg_resources)
+ reload(setuptools)
     else:
- import pkg_resources
+ reload(pkg_resources)
+ import setuptools

 if sys.platform == 'win32':
     def quote(c):