[Distutils] Namespace packages and egg-info confusion when using bdist_rpm

Stanley A. Klein sklein at cpcug.org
Thu Jul 26 19:37:57 CEST 2007


On Thu, July 26, 2007 12:46 pm, Phillip J. Eby wrote:
> At 12:34 PM 7/26/2007 -0400, Stanley A. Klein wrote:
>>I disabled the __init__.py's on the namespace packages by renaming them.
>> A
>>sys.modules.keys() shows the namespace packages in the list.  Then I
>>interactively did the first three statements of the test_traits.py
>>program:
>>
>>import unittest
>>from enthought.traits.api import *
>>import enthought.traits.standard as standard
>>
>>The last statement failed with an error:
>>
>>Traceback (most recent call last):
>>   File "test_traits.py", line 23, in ?
>>     import enthought.traits.standard as standard
>>AttributeError: 'module' object has no attribute 'traits'
>>
>>If I then interactively do "import enthought.traits.standard", it works
>>without error.
>
> Aha.  Try this.  In each nspkg.pth file, add "import x" lines, where
> "x" is any namespace package referenced in that file.  That is, if
> the file refers to enthought.traits, add a line saying "import
> enthought.traits" at the *end* of the file.  Do this in every file,
> for every module mentioned in that file.  Get rid of the
> __init__.py's and give it a whirl.
>
> I think that what's happening is that the .pth files I'm generating
> are not settting sys.modules['enthought'].traits =
> sys.modules['enthought.traits']; adding the import statements should
> fix that.  If it works, I'll change setuptools to generate the files
> with the added import statements.
>
> Thanks for taking the time to help track this down.  It looks like I
> only tested this with top--level namespace packages (e.g. peak.*,
> zope.*) and not sub-packages (like enthought.traits).
>

The only three namespace packages are enthought, enthought.traits, and
enthought.traits.ui.

Here is the full list of pth files:

[stan at localhost ~]$ ls /usr/lib/python2.4/site-packages/enthought.*pth
/usr/lib/python2.4/site-packages/enthought.etsconfig-2.0b1.dev_r12883-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.io-2.0b1.dev_r12810-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.naming-2.0b2.dev_r12810-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.pyface-2.0b2.dev_r12984-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.resource-2.0b1.dev_r12810-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.resource_type-2.0b2.dev_r12810-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.sweet_pickle-2.0b2.dev_r12810-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.traits-2.0b2.dev_r12984-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.traits.ui.wx-2.0b2.dev_r12984-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.type_manager-2.0b1.dev_r12810-py2.4-nspkg.pth
/usr/lib/python2.4/site-packages/enthought.util-2.0b2.dev_r12981-py2.4-nspkg.pth


Most of the files looked like:

import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'],
*('enthought',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m =
not ie and sys.modules.setdefault('enthought',new.module('enthought')); mp
= (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and
mp.append(p)

I left those alone, and did only the following two:

[stan at localhost ~]$ cat
/usr/lib/python2.4/site-packages/enthought.traits-2.0b2.dev_r12984-py2.4-nspkg.pth
import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'],
*('enthought',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m =
not ie and sys.modules.setdefault('enthought',new.module('enthought')); mp
= (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and
mp.append(p)
import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'],
*('enthought', 'traits')); ie =
os.path.exists(os.path.join(p,'__init__.py')); m = not ie and
sys.modules.setdefault('enthought.traits',new.module('enthought.traits'));
mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and
mp.append(p)
import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'],
*('enthought', 'traits', 'ui')); ie =
os.path.exists(os.path.join(p,'__init__.py')); m = not ie and
sys.modules.setdefault('enthought.traits.ui',new.module('enthought.traits.ui'));
mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and
mp.append(p)
import enthought
import enthought.traits
import enthought.traits.ui


and

[stan at localhost ~]$ cat
/usr/lib/python2.4/site-packages/enthought.traits.ui.wx-2.0b2.dev_r12984-py2.4-nspkg.pth
import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'],
*('enthought',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m =
not ie and sys.modules.setdefault('enthought',new.module('enthought')); mp
= (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and
mp.append(p)
import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'],
*('enthought', 'traits')); ie =
os.path.exists(os.path.join(p,'__init__.py')); m = not ie and
sys.modules.setdefault('enthought.traits',new.module('enthought.traits'));
mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and
mp.append(p)
import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'],
*('enthought', 'traits', 'ui')); ie =
os.path.exists(os.path.join(p,'__init__.py')); m = not ie and
sys.modules.setdefault('enthought.traits.ui',new.module('enthought.traits.ui'));
mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and
mp.append(p)
import enthought
import enthought.traits
import enthought.traits.ui


I had the same error.  Should I have put in an "import enthought" in all
the others?


Stan Klein



More information about the Distutils-SIG mailing list