Author lemburg
Recipients BTaskaya, Mark.Shannon, brandtbucher, brett.cannon, eric.snow, gvanrossum, indygreg, larry, lemburg, methane, nascheme, ncoghlan, ronaldoussoren, shihai1991
Date 2021-09-04.09:19:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <226d97ff-889a-9575-7e8e-42ab3ee19af3@egenix.com>
In-reply-to <1630717705.59.0.552743885416.issue45020@roundup.psfhosted.org>
Content
FWIW, I've not found the importer for frozen modules to be lacking
features. When using frozen modules, you don't expect to see source
code, so the whole part about finding source code is not really
relevant for that use case.

The only lacking part I found regarding frozen modules is support
for these in pkgutil.py. But that's easy to add:

--- /home/lemburg/egenix/projects/PyRun/Python-3.8.0/Lib/pkgutil.py
2019-10-14 1>
+++ ./Lib/pkgutil.py    2019-11-17 11:36:38.404752218 +0100
@@ -315,20 +315,27 @@
         return self.etc[2]==imp.PKG_DIRECTORY

     def get_code(self, fullname=None):
+        # eGenix PyRun needs pkgutil to also work for frozen modules,
+        # since pkgutil is used by the runpy module, which is needed
+        # to implement the -m command line switch.
+        if self.code is not None:
+            return self.code
         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)
-                self.code = compile(source, self.filename, 'exec')
-            elif mod_type==imp.PY_COMPILED:
-                self._reopen()
-                try:
-                    self.code = read_code(self.file)
-                finally:
-                    self.file.close()
-            elif mod_type==imp.PKG_DIRECTORY:
-                self.code = self._get_delegate().get_code()
+        mod_type = self.etc[2]
+        if mod_type == imp.PY_FROZEN:
+            self.code = imp.get_frozen_object(fullname)
+            return self.code
+        elif mod_type==imp.PY_SOURCE:
+            source = self.get_source(fullname)
+            self.code = compile(source, self.filename, 'exec')
+        elif mod_type==imp.PY_COMPILED:
+            self._reopen()
+            try:
+                self.code = read_code(self.file)
+            finally:
+                self.file.close()
+        elif mod_type==imp.PKG_DIRECTORY:
+            self.code = self._get_delegate().get_code()
         return self.code

     def get_source(self, fullname=None):
History
Date User Action Args
2021-09-04 09:19:42lemburgsetrecipients: + lemburg, gvanrossum, brett.cannon, nascheme, ronaldoussoren, ncoghlan, larry, methane, Mark.Shannon, eric.snow, indygreg, brandtbucher, BTaskaya, shihai1991
2021-09-04 09:19:41lemburglinkissue45020 messages
2021-09-04 09:19:41lemburgcreate