[Distutils] bizarre behavior with wheels and namespace packages
Brian Wickman
wickman at gmail.com
Sat Mar 8 05:15:20 CET 2014
Not sure if this belongs on distutils-sig or import-sig, but I'm
experiencing slightly odd behavior with wheels and namespace packages.
Fetch a namespace package source distribution, e.g. twitter.common.python,
and build two copies of it, one with bdist_egg and one with bdist_wheel.
This leaves me with:
twitter.common.python-0.3.1-py2.6.egg
twitter.common.python-0.3.1-py26-none-any.whl
Explode them into the following directories (respectively):
egg_dist
whl_dist
Then attempt:
PYTHONPATH=egg_dist python -c 'import twitter.common.python'
(works)
PYTHONPATH=whl_dist python -c 'import twitter.common.python'
(drumroll)
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named twitter.common.python
This is slightly unexpected. Absent from the .whl distribution are the
__init__.pys with the proper declare_namespace declarations. Even more
bizarrely:
PYTHONPATH=whl_dist python -c 'import pkg_resources'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File
"/Users/wickman/Python/CPython-2.6.9/lib/python2.6/site-packages/pkg_resources.py",
line 2736, in <module>
add_activation_listener(lambda dist: dist.activate())
File
"/Users/wickman/Python/CPython-2.6.9/lib/python2.6/site-packages/pkg_resources.py",
line 698, in subscribe
callback(dist)
File
"/Users/wickman/Python/CPython-2.6.9/lib/python2.6/site-packages/pkg_resources.py",
line 2736, in <lambda>
add_activation_listener(lambda dist: dist.activate())
File
"/Users/wickman/Python/CPython-2.6.9/lib/python2.6/site-packages/pkg_resources.py",
line 2274, in activate
list(map(declare_namespace,
self._get_metadata('namespace_packages.txt')))
File
"/Users/wickman/Python/CPython-2.6.9/lib/python2.6/site-packages/pkg_resources.py",
line 1870, in declare_namespace
path = sys.modules[parent].__path__
KeyError: 'twitter'
So even pkg_resources is surprised as well. If I do the following:
PYTHONPATH=whl_dist python -c 'import site; site.addsitedir("whl_dist");
import twitter.common.python'
then it works, since the twitter.common.python-0.3.1-py2.6-nspkg.pth gets
processed properly and module.__path__s populated accordingly. I would
expect pkg_resources to handle this fine but apparently it doesn't.
Any ideas? Bug in pkg_resources, wheel or PEBKAC?
Thanks!
~brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20140307/50a80b75/attachment-0001.html>
More information about the Distutils-SIG
mailing list