feat(launcher): embed python#4414
Conversation
| let console_snippet = if console { | ||
| r#" sys.stdout = sys.stderr = open("CONOUT$", "w"); sys.stdin = open("CONIN$", "r");"# | ||
| } else { |
There was a problem hiding this comment.
This is very jank, but apart from using the console subsystem, i've not been able to find another solution for this. It also potentially doesn't show output between starting the interpreter and running this snippet
Perhaps anki-console could be changed from a wrapper that just spawns anki.exe with env vars to a stripped-down version of the launcher but with the console subsystem
|
I've just come across this nugget on https://docs.python.org/3/library/site.html
Which means that the venv activation script (
EDIT: I've used bindgen on the 3.9/3.13 lin/win cpython headers to codegen NB: The pythonistas have realised this is very inconvenient (PEP 741), and so from 3.14 onwards we can set |
instead of just libpython's path we now get and cache the nodot version and venv bin path
we can't rely on the very high level layer alone anymore
no idea why windows needs an explicit decl, possible compiler bug?
1922a53 to
dbc7adc
Compare
|
This is some impressive technical work Llama, and ties in to the decision we need to make as mentioned on #4390 (comment). I might create a new issue to discuss, and respond there. |
## Linked issue Closes ankitects#4556 Closes ankitects#4557 Closes ankitects#4144 Closes ankitects#4151 Closes ankitects#4152 Closes ankitects#4153 Closes ankitects#4229 Closes ankitects#4356 Closes ankitects#4401 Closes ankitects#4403 Closes ankitects#4519 Closes ankitects#4523 Closes ankitects#4390 Closes ankitects#4414 Closes ankitects#4484 ## Summary / motivation After 4 months of exploring Briefcase for packaging, we're confident it solves most problems with the uv launcher with less complexity and at a lower maintenance cost, especially with the parallel work on the release CI, which we already used to make 5 releases. This also removes platform-specific packaging/signing code used to produce macOS dmg files and Windows NSIS installers, which is now largely handled by Briefcase and the release CI. The custom install scripts for Linux are mostly preserved under qt/installer/linux-template and used in the Briefcase build. ## How to test - [ ] No build problems. - [ ] The `tools/build-installer` scripts still work. - [ ] No CI/release workflow issues. - [ ] No user-visible changes in dev environment and Briefcase build.
Closes #4151
Looked into why embedding statically/dynamically python would need version-scoped installers, and found that PyConfig's layout depends on the targetted version. If we went that route, we could use pyembed (of the dead pyoxidizer family) or pyo3 and link against a specific version
Instead, i've opted to link against libpython at runtime, using the venv bin* to get the libpath for the currently selected version (3.9/3.13 etc.), using the venv activation script to setup up
sys.path,sys.prefixetc, and only relying on the 3.x stable api and The Very High Level Layer to setup and start the interpreter. If it fails, it'll fallback to the usual launch method of spawning the venv binWasn't able to find any examples of run-time linking python, but i did see a mention in the python manual so we're not doing anything untoward here (hopefully)
Portability: this Just Works™ on my wsl ubuntu and win10 machines (after wrestling with the quirks of 3.9 and 3.13 on each platform), but i've not been able to test on macs
Overhead: once on first-startup to get and cache libpython's path, and none as far as i can tell on runtime
*this may seem weird but there's precedence: pyo3 invokes python in build scripts