Marc-Andre Lemburg added the comment:

Here's the fix we're applying in pyrun to make -m imports work at least for 
top-level modules:

--- /home/lemburg/orig/Python-2.7.3/Lib/pkgutil.py      2012-04-10 
01:07:30.000000000 +0200
+++ pkgutil.py  2012-09-24 22:53:30.982526065 +0200
@@ -273,10 +273,21 @@ class ImpLoader:
     def is_package(self, fullname):
         fullname = self._fix_name(fullname)
         return self.etc[2]==imp.PKG_DIRECTORY

     def get_code(self, fullname=None):
+        if self.code is not None:
+            return self.code
+        fullname = self._fix_name(fullname)
+        mod_type = self.etc[2]
+        if mod_type == imp.PY_FROZEN:
+            self.code = imp.get_frozen_object(fullname)
+            return self.code
+        else:
+            return self._get_code(fullname)
+
+    def _get_code(self, fullname=None):
         fullname = self._fix_name(fullname)
         if self.code is None:
             mod_type = self.etc[2]
             if mod_type==imp.PY_SOURCE:
                 source = self.get_source(fullname)

This makes runpy work for top-level frozen modules, but it's really only 
partial solution, since pkgutil would need to get such support in more places.

We also found that for some reason, runpy/pkgutil does not work for frozen 
package imports, e.g. wsgiref.util. The reasons for this appear to be deeper 
than just in the pkgutil module. We don't have a solution for this yet. It is 
also not clear whether the problem still exists in Python 3.x. The __path__ 
attribute of frozen modules was changed in 3.0 to be a list like for all other 
modules, however, applying that change to 2.x lets runpy/pkgutil fail 
altogether (not even the above fix works anymore).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16027>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to