Skip to content

Commit

Permalink
loader: implement FrozenImporter source loading from .py files
Browse files Browse the repository at this point in the history
Provide basic FrozenImporter.get_source() implementation that allows
loading of source from .py files that have been collected by hooks
as data files.
  • Loading branch information
rokm authored and bwoodsend committed Apr 6, 2021
1 parent 2253478 commit bab86a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions PyInstaller/loader/pyimod03_importers.py
Expand Up @@ -328,6 +328,15 @@ def get_source(self, fullname):
Return None.
"""
if fullname in self.toc:
# Try loading .py file from the filesystem
filename = pyi_os_path.os_path_join(
SYS_PREFIX,
fullname.replace('.', pyi_os_path.os_sep) + '.py')
try:
with open(filename, 'r') as fp:
return fp.read()
except FileNotFoundError:
pass
return None
else:
# ImportError should be raised if module not found.
Expand Down
3 changes: 3 additions & 0 deletions news/5697.feature.rst
@@ -0,0 +1,3 @@
Provide basic implementation for ``FrozenImporter.get_source()`` that
allows reading source from ``.py`` files that are collected by hooks as
data files.

0 comments on commit bab86a0

Please sign in to comment.