Conversation
qt/launcher/src/platform/windows.rs
Outdated
| 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. |
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