[Distutils] Setuptools, namespace packages, --single-version-externally-managed

P.J. Eby pje at telecommunity.com
Wed May 6 02:03:23 CEST 2009

At 04:35 PM 5/5/2009 -0500, Ian Bicking wrote:
>Any ideas on this?  Phillip?
>On Fri, May 1, 2009 at 5:07 PM, Ian Bicking 
><<mailto:ianb at colorstudy.com>ianb at colorstudy.com> wrote:
>So, a bit of a problem came up with pip and namespace 
>packages.  Here's my understanding of what's going on:
>When you install a namespace package with pip, it uses install 
>--single-version-externally-managed, and generally the namespace 
>directory is empty and there's a *.nspkg.pth file that has this:
>import sys,new,os; p = 
>*('<NAMESPACE>',)); ie = 
>os.path.exists(os.path.join(p,'__init__.py')); m = not ie and 
>sys.modules.setdefault('zope',new.module('zope')); mp = (m or []) 
>and m.__dict__.setdefault('__path__',[]); (p not in mp) and mp.append(p)
>So the lack of an __init__.py file doesn't really matter, because 
>it's created right there, and has its __path__ added to.  But 
>there's a problem when there's another namespace package elsewhere 
>on the path, that wasn't installed with pip (or Setuptools) and uses 
>pkgutils.extend_path(__path__, __name__).  This doesn't get 
>imported because of that .pth file, and the .pth file doesn't itself 
>use extend_path, so the path isn't searched.  This is currently 
>happening with Zope packages installed with plain distutils, then 
>another package installed with the zope namespace elsewhere with 
>pip.  (When using easy_install, I think 
>pkg_resource.declare_namespace comes into play somewhere, and this 
>seems to handle this case, but I'm not sure why the installation is 
>different with pip.)
>So... what should pip be doing differently to make this work?

Heck if I know.  IIUC, this should work as long as the namespace 
declaration gets invoked at some point.

But I don't know of any way to ensure that, except for pip to write 
its own __init__.py (invoking declare_namespace()) and gets rid of 
the nspkg.pth file.

More information about the Distutils-SIG mailing list