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

site.addsitedir order is incorrect #1338

Open
mhsmith opened this issue Mar 3, 2025 · 1 comment
Open

site.addsitedir order is incorrect #1338

mhsmith opened this issue Mar 3, 2025 · 1 comment
Labels
Milestone

Comments

@mhsmith
Copy link
Member

mhsmith commented Mar 3, 2025

Originally reported by @timrid in beeware/briefcase#2173 (comment)


To the problem with .pth files on Android: When processing the .pth file I get the following error before the main module is even started. On windows executing the startup code via .pth is no problem. I guess that java.chaquopy.import_override modifies some behavior, so that _socket is not loaded when executing my startup code.

...
W/python.stderr: Error processing line 1 of /data/data/com.example.helloworld/files/chaquopy/AssetFinder/app/__briefcase_startup__.pth:
W/python.stderr: 
W/python.stderr:   Traceback (most recent call last):
W/python.stderr:     File "<frozen site>", line 206, in addpackage
W/python.stderr:     File "<string>", line 1, in <module>
W/python.stderr:     File "import.pxi", line 60, in java.chaquopy.import_override
W/python.stderr:     File "/data/data/com.example.helloworld/files/chaquopy/AssetFinder/app/__briefcase_startup__.py", line 4, in <module>
W/python.stderr:       import socket
W/python.stderr:     File "stdlib/socket.py", line 52, in <module>
W/python.stderr:   ModuleNotFoundError: No module named '_socket'
W/python.stderr:
W/python.stderr: Remainder of file ignored
D/MainActivity: Running main module helloworld
...
@mhsmith mhsmith added the bug label Mar 3, 2025
@mhsmith mhsmith added this to the 17.0 milestone Mar 3, 2025
@mhsmith
Copy link
Member Author

mhsmith commented Mar 3, 2025

sys.path correctly follows the dependency order (app, requirements, stdlib). However, initialization should happen in the reverse order, low level to high level. And in case .pth files scan the whole of sys.path, we should create all path entries before running any .pth files.

So the order should be:

  • Add all sys.path entries, without running any code from those paths.
  • Run site.addsitedir in the order (stdlib, requirements, app)

@mhsmith mhsmith changed the title site.addsitedir order is incorrect site.addsitedir order is incorrect Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant