fix(py_loader,rs_port): bootstrap Python home on Windows to prevent CPython init_fs_encoding failures#734
Draft
k5602 wants to merge 1 commit intometacall:developfrom
Draft
fix(py_loader,rs_port): bootstrap Python home on Windows to prevent CPython init_fs_encoding failures#734k5602 wants to merge 1 commit intometacall:developfrom
k5602 wants to merge 1 commit intometacall:developfrom
Conversation
Member
|
it's good but I'm not sure if this is the approach we should do, have you seen the Linux distributable that has a profile file for storing all env vars? I was thinking about that |
Member
|
I reviewed the code and it's actually very good. We should investigate anyway how are they installed, my original idea can be combined with yours, which was finding the PYTHONPATH etc based on the libpython.so path. Because they can be relinked dynamically. |
Member
|
When it runs in python.exe, do we assume PYTHONPATH is correct? |
This was referenced Apr 8, 2026
Member
|
I'm leaving this as draft until we design this: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes Windows CI instability in the Rust port caused by Python embedded initialization failing with:
Fatal Python error: init_fs_encodingModuleNotFoundError: No module named 'encodings'The fix ensures Python home/bootstrap paths are resolved consistently when running
cargo testagainst installed MetaCall binaries on Windows.Root cause
rs_porttests were running against installed MetaCall artifacts (from the install script) where runtime Python bootstrap context was not guaranteed at process startup. In this context, embedded Python could initialize without a validPYTHONHOME, causing stdlib bootstrap failure.What changed
1) Python loader configuration (proper loader-side fix)
source/loaders/py_loader/data/py_loader.json.in.python_hometo py_loader configuration.py_loaderCMake to use this custom template.search_pathsgeneration for development/install configs.Files:
source/loaders/py_loader/data/py_loader.json.insource/loaders/py_loader/CMakeLists.txt2) Python loader runtime bootstrap
py_loaderthat:python_homefrom loader config,PYTHONHOMEif already set,PYTHONHOMEbeforePy_InitializeEx(0).File:
source/loaders/py_loader/source/py_loader_impl.c3) Rust port compatibility fallback (for older installed packages)
rs_portinit path:PYTHONHOMEis unset, infer it fromMETACALL_PYTHONHOMEand runtime layout,.../runtimes/pythonwhen present.METACALL_PYTHONHOMEfrommetacall-sysbuild metadata on Windows.Files:
source/ports/rs_port/src/init.rssource/ports/rs_port/sys/src/lib.rsWhy this approach
Validation
inlines_testbefore fix).inlines_testpasses,Type of change
Checklist
./docker-compose.sh testand attached the output.OPTION_BUILD_ADDRESS_SANITIZERor./docker-compose.sh test-address-sanitizerandOPTION_TEST_MEMORYCHECK.OPTION_BUILD_THREAD_SANITIZERor./docker-compose.sh test-thread-sanitizer.Helgrindin case my code works with threading.make clang-formatin order to format my code and my code follows the style guidelines.