Comment 3 for bug 129299

Revision history for this message
bwinton (bwinton+bzr) wrote :

I traced it down to line 183 raising an exception. (ImportError, I believe...) But there wasn't anything useful

lines 181-193 look like:
    for name in plugin_names:
        try:
            exec "import bzrlib.plugins.%s" % name in {}
        except KeyboardInterrupt:
            raise
        except Exception, e:
            ## import pdb; pdb.set_trace()
            if re.search('\.|-| ', name):
                warning('Unable to load plugin %r from %r: '
                    'It is not a valid python module name.' % (name, d))
            else:
                warning('Unable to load plugin %r from %r' % (name, d))
            log_exception_quietly()

I can get the same error by adding a trailing slash to one of the entries in sys.path, and trying to load a file from that entry.

Z:\>dir c:\progra~1\Python\lib\bdb*
 Volume in drive C has no label.
 Volume Serial Number is 204B-2F2E

 Directory of c:\progra~1\Python\lib

12/05/2006 02:17 PM 20,756 bdb.py
11/07/2007 10:52 AM 18,353 bdb.pyc
11/07/2007 10:52 AM 18,353 bdb.pyo
               3 File(s) 57,462 bytes
               0 Dir(s) 126,196,838,400 bytes free

Z:\>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'C:\\WINDOWS\\system32\\python25.zip', 'c:\\progra~1\\Python\\DLLs', 'c:\\p
rogra~1\\Python\\lib', 'c:\\progra~1\\Python\\lib\\plat-win', 'c:\\progra~1\\Pyt
hon\\lib\\lib-tk', 'c:\\progra~1\\Python', 'c:\\progra~1\\Python\\lib\\site-pack
ages', 'c:\\progra~1\\Python\\lib\\site-packages\\PIL', 'c:\\progra~1\\Python\\l
ib\\site-packages\\win32', 'c:\\progra~1\\Python\\lib\\site-packages\\win32\\lib
', 'c:\\progra~1\\Python\\lib\\site-packages\\Pythonwin']
>>> sys.path = ['', 'C:\\WINDOWS\\system32\\python25.zip', 'c:\\progra~1\\Python
\\DLLs', 'c:\\progra~1\\Python\\lib\\', 'c:\\progra~1\\Python\\lib\\plat-win', '
c:\\progra~1\\Python\\lib\\lib-tk', 'c:\\progra~1\\Python', 'c:\\progra~1\\Pytho
n\\lib\\site-packages', 'c:\\progra~1\\Python\\lib\\site-packages\\PIL', 'c:\\pr
ogra~1\\Python\\ib\\site-packages\\win32', 'c:\\progra~1\\Python\\lib\\site-pack
ages\\win32\\lib', 'c:\\progra~1\\Python\\lib\\site-packages\\Pythonwin']
>>> sys.path
['', 'C:\\WINDOWS\\system32\\python25.zip', 'c:\\progra~1\\Python\\DLLs', 'c:\\p
rogra~1\\Python\\lib\\', 'c:\\progra~1\\Python\\lib\\plat-win', 'c:\\progra~1\\P
ython\\lib\\lib-tk', 'c:\\progra~1\\Python', 'c:\\progra~1\\Python\\lib\\site-pa
ckages', 'c:\\progra~1\\Python\\lib\\site-packages\\PIL', 'c:\\progra~1\\Python\
\ib\\site-packages\\win32', 'c:\\progra~1\\Python\\lib\\site-packages\\win32\\li
b', 'c:\\progra~1\\Python\\lib\\site-packages\\Pythonwin']
>>> import bdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named bdb
>>> import cgi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cgi

etc, etc...

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52662 suggests that you should call os.path.abspath and os.path.exists on the arguments before adding them to sys.path, which we oddly don't seem to do. (Oh, but we set the __path__ of the plugins module, which should do something similar.)

And in a tangent, we seem to set it twice in a row, once at line 92, and then again a few instructions later, at line 129. Should those both really be there?