[Distutils] Setuptools: problem with setuptools.command.bdist_egg:write_stub

Phillip J. Eby pje at telecommunity.com
Thu Apr 17 05:13:17 CEST 2008


At 06:43 PM 4/16/2008 -0500, Ian Bicking wrote:
>In setuptools.command.bdist_egg:write_stub() Setuptools writes this
>function out alongside .so files:
>
>def __bootstrap__():
>     global __bootstrap__, __loader__, __file__
>     import sys, pkg_resources, imp
>     __file__ = pkg_resources.resource_filename(__name__,<resource filename>)
>     del __bootstrap__, __loader__
>     imp.load_dynamic(__name__,__file__)
>__bootstrap__()
>
>This is problematic on App Engine, as the .py file is loaded because .so
>files cannot be imported.  However, unlike a zip file (where I assume
>this function is intended to be used) there is no __loader__.  As a
>result "del __loader__" fails.
>
>I submitted this to App Engine
>(http://code.google.com/p/googleappengine/issues/detail?id=229), but I
>also think Setuptools is creating an unnecessarily fragile function here.

Until now, the only place the .py file would be imported in this 
scenario is in a zipfile...  which ensures the loader would 
exist.  If you're simply unzipping an egg here, you'll need to delete 
the .py as well as the .so, since neither is of any use here.

Note that unless App Engine supports imp.load_dynamic(), all you're 
going to do by changing this is move the error one line down.  I'm 
not sure I see how that's helpful.  Certainly, though, if you want to 
provide a setuptools patch to add "__loader__ = None" before the 
"del" line, that would work.  (I presume you are patching imp's 
load_dynamic to raise an ImportError, instead of the NameError or 
whatever you're currently getting from the del operation.)

Of course, you'll have to rebuild any eggs you're using this way, 
since the bootstrap code is placed there by bdist_egg, not easy_install.



More information about the Distutils-SIG mailing list