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

Phillip J. Eby pje at telecommunity.com
Thu Jul 26 00:10:54 CEST 2007


At 04:42 PM 7/25/2007 -0400, Stanley A. Klein wrote:
>I've been trying to build rpms of enthought system components.  Some of
>them use namespace packages.  Those packages have the required __init__.py
>files containing
>"__import__('pkg_resources').declare_namespace(__name__)".
>
>According to the Setuptools Guide, these __init__.py files are not to be
>packaged when using "system" packaging (such as bdist_rpm) and when I run
>bdist_rpm they are not included in the rpms.  However, there are egg-info
>directories and nspkg.pth files produced, included in the rpms, and
>installed in site-packages.

So far, so good - that's exactly how it's supposed to work.

>   When I tried to run the enthought example
>applications, I had various kinds of import failures.  I found that fixing
>them required putting the unpackaged __init__.py files into the relevant
>directories in the namespace packages.
>
>The various rpms were being placed in the proper locations where they
>should have been found for importing.  There were some strange errors,
>such as in one case when I tried to test the imports interactively an
>"import a.b.c" worked, but an "import a.b.c as c" failed.
>
>Before putting in the __init__.py files, I tried removing the egg-info and
>nspkg.pth files from site_packages.  That did not improve things.

It sure as heck wouldn't.  They need to be there, and the nspkg.pth 
files need to be processed by Python during its startup.


>I think setuptools is somehow not properly processing bdist_rpm if there
>are namespace packages involved.  Also, the setuptools don't seem to have
>an option to not create the egg info and nspkg.pth files and/or to not
>package them if bdist_rpm is being used.

This is by design.  It is almost certainly the case that either:

1. the nspkg.pth files are not being processed when Python starts

2. something is deleting the namespace packages from sys.modules 
between the time the .pth files are processed, and the time you 
attempt to import them.

To verify this, I would say, start Python with the bdist_rpms 
installed as directed (i.e., don't mess with what's installed), and 
see if there are sys.modules entries for the namespace 
package(s).  If there are, then the problem is happening later - 
i.e., something being done by your code.  If the namespace packages 
aren't in sys.modules, then there is a problem with the .pth files at 
startup; try using "python -v" to see if there are any errors shown.



More information about the Distutils-SIG mailing list