Had an idea how to fix this in zc.buildout (see attached patch). Of course it
leads to some activated namespaces which should be inactive but as this is
mostly relevant for "buildout init" I hope it's anyway acceptable.

Comments welcome.

fs
Index: src/zc/buildout/easy_install.py
===================================================================
--- src/zc/buildout/easy_install.py	(Revision 124993)
+++ src/zc/buildout/easy_install.py	(Arbeitskopie)
@@ -286,8 +286,16 @@
 # The code, below, then, runs under -S, indicating that site.py should
 # not be loaded initially.  It gets the initial sys.path under these
 # circumstances, and then imports site (because Python 2.6's distutils
-# will want it, as mentioned above). It then reinstates the old sys.path
-# value. Then it removes namespace packages (created by the setuptools
+# will want it, as mentioned above). 
+# pkg_resouces must be imported now because it will activate all namespace 
+# packages available in sys.path on import time. It assumes that each namespace
+# is also available in sys.modules (in 'declare_namespace')  which is not the 
+# case after sys.path is reset. This leads to problems if a three-level 
+# namespace package (e.g. peak/util/symbols.py) is available in sys.path. See
+# http://mail.python.org/pipermail/distutils-sig/2012-April/018451.html
+# for further information.
+# Afterwards it reinstates the old sys.path value. 
+# Then it removes namespace packages (created by the setuptools
 # code above) from sys.modules.  It identifies namespace packages by
 # iterating over every loaded module.  It first looks if there is a
 # __path__, so it is a package; and then it sees if that __path__ does
@@ -301,6 +309,7 @@
 import sys,os;\
 p = sys.path[:];\
 import site;\
+import pkg_resources;\
 sys.path[:] = p;\
 [sys.modules.pop(k) for k, v in sys.modules.items()\
  if hasattr(v, '__path__') and len(v.__path__)==1 and\
_______________________________________________
Distutils-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/distutils-sig

Reply via email to