Author lemburg
Recipients Arfrever, brett.cannon, lemburg, ncoghlan
Date 2012-09-25.14:06:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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/      2012-04-10 01:07:30.000000000 +0200
+++  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).
Date User Action Args
2012-09-25 14:06:20lemburgsetrecipients: + lemburg, brett.cannon, ncoghlan, Arfrever
2012-09-25 14:06:20lemburgsetmessageid: <>
2012-09-25 14:06:20lemburglinkissue16027 messages
2012-09-25 14:06:19lemburgcreate