diff --git a/PyInstaller/loader/pyimod03_importers.py b/PyInstaller/loader/pyimod03_importers.py index 40931371f8..9de19fdfbd 100644 --- a/PyInstaller/loader/pyimod03_importers.py +++ b/PyInstaller/loader/pyimod03_importers.py @@ -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. diff --git a/news/5697.feature.rst b/news/5697.feature.rst new file mode 100644 index 0000000000..b4fb19be26 --- /dev/null +++ b/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.