Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loader: implement FrozenImporter source loading from .py files #5697

Merged
merged 1 commit into from Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.