Gracefully handling missing dependencies in bootstrap.py

Bug #410528 reported by Erik Karulf
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Buildout
Fix Committed
Undecided
Unassigned

Bug Description

I was using zc.buildout on a brand-new ubuntu machine when I was met with the following cryptic error message.

18:46 erik@fozzie % python bootstrap.py
Traceback (most recent call last):
  File "bootstrap.py", line 76, in <module>
    ws.find(pkg_resources.Requirement.parse('setuptools')).location
AttributeError: 'NoneType' object has no attribute 'location'
Exit 1

It turns out that I did not have the setuptools package installed.

Would it be possible to catch and display the error in a more graceful way?

try:
    import setuptools
except ImportError:
    print "setuptools dependency not satisfied."
    import sys
    sys.exit(1)

Tags: bootstrap
Revision history for this message
Jim Fulton (jim-zope) wrote : Re: [Bug 410528] [NEW] Gracefully handling missing dependencies in bootstrap.py

On Fri, Aug 7, 2009 at 7:49 PM, Erik Karulf<email address hidden> wrote:
> Public bug reported:
>
> I was using zc.buildout on a brand-new ubuntu machine when I was met
> with the following cryptic error message.
>
> 18:46 erik@fozzie % python bootstrap.py
> Traceback (most recent call last):
>  File "bootstrap.py", line 76, in <module>
>    ws.find(pkg_resources.Requirement.parse('setuptools')).location
> AttributeError: 'NoneType' object has no attribute 'location'
> Exit 1
>
> It turns out that I did not have the setuptools package installed.
>
> Would it be possible to catch and display the error in a more graceful
> way?

My guess is that setuptools is installed, but without it's egg info.
Were you using the system Python?

Can you import pkg_resources?

In any case, I *can* an a check for this situation. I shouldn't have to, but ...

Jim

--
Jim Fulton

Revision history for this message
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):

Changed in zc.buildout:
status: New → Confirmed
Revision history for this message
Wichert Akkerman (wichert) wrote :

My initial patch was needlessly complicated, so I've attached a better version. There are two basic changes I have made:

* I try to import setuptools as well to make sure all of setuptools is available. This is required because Ubuntu defaults to only install pkg_resources.

* I always reload sys.modules('pkg_resources'). This is needed because ez['use_setuptools'](..) may import the wrong pkg_resources.

Changed in zc.buildout:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.