-
-
Notifications
You must be signed in to change notification settings - Fork 474
Description
Describe the bug
.pth that are located in the app_packages folder are not correctly processed on all platforms.
This leads to import errors with some packages. A prominent example is pywin32 (see here and here).
In addition, any Python code can be executed via .pth file at startup. This can also be used, for example, to establish a connection with a remote debugger (see here and here).
The following platforms are affected by this:
- Windows App
- Windows VisualStudio
- Linux Flatpak
- Linux System
- Linux AppImage (I guess, but I am not 100% sure. I could not test this so far.)
- macOS App
- macOS XCode
- iOS XCode
- Web
The following platforms are not affected by this:
- Android (but there is another bug as noted here)
Steps to reproduce
Add the following to pyproject.toml
...
[tool.briefcase.app.helloworld]
requires = [
"git+https://github.com/timrid/pth-execution-checker@main"
]
...
and somewhere in the app call
import pth_execution_checker
if not pth_execution_checker.pth_executed:
raise RuntimeError(".pth file not processed...")
Expected behavior
.pth files should be processed correctly on all platforms.
Screenshots
No response
Environment
- Operating System: Windows, Linux, macOS
- Python version: 3.13
- Software versions:
- Briefcase: 0.3.22
Logs
Additional context
One solution would be to remove app and app_packages entirely and move all packages to site-packages, as described in #2195. But this was rejected by @freakboy3742. But he made the following suggestion (Link):
The site_packages folder isn't inherently special - it's just on the site list by default because it's a location tied to a the Python interpreter's libdir. The method site.addsitedir() exists to add additional site folders - I'm fairly certain the fix here is to use this method to add app_packages as a site dir, rather than just adding it to PYTHONPATH/sys.path as the stub is currently doing.