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

building: add .py suffix to entry-point scripts without suffix #8049

Merged
merged 1 commit into from Oct 29, 2023

Conversation

rokm
Copy link
Member

@rokm rokm commented Oct 28, 2023

If the entry-point script has no suffix, append the .py suffix to the filename passed to the compile function when byte-compiling the script for collection.

This ensures that the entry-point script filename never coincides with executable filename, especially in POSIX builds, where executables have no suffix either (and their name is based on the entry-point script basename by default). Entry-point script having the same filename as the executable causes issues when traceback (and linecache) try to access source code for it, an in the process end up reading the executable file if it happens to be in the current working directory.

Fixes #8046.

If the entry-point script has no suffix, append the `.py` suffix
to the filename passed to the `compile` function when byte-compiling
the script for collection.

This ensures that the entry-point script filename never coincides with
executable filename, especially in POSIX builds, where executables have
no suffix either (and their name is based on the entry-point script
basename by default). Entry-point script having the same filename as
the executable causes issues when `traceback` (and `linecache`)
try to access source code for it, an in the process end up reading
the executable file if it happens to be in the current working directory.
@rokm
Copy link
Member Author

rokm commented Oct 28, 2023

Fun fact: regardless of what the suffix entry point-script has (or does not have), the __file__ attribute at run-time is always {basename}.py. That's because we store only basename in the PKG TOC, and the bootloader prepends _MEIPASS and adds .py suffix at run-time (here).

The problematic part is the filename that is embedded in the code object when byte-compiling using compile(), where we pass the original source filename.

@rokm rokm merged commit 587681f into pyinstaller:develop Oct 29, 2023
18 checks passed
@rokm rokm deleted the fix-8046 branch October 29, 2023 10:40
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants