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 committed Apr 4, 2021
1 parent f77294a commit b8168a2
Showing 1 changed file with 9 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

0 comments on commit b8168a2

Please sign in to comment.