pyodide/python/pyodide_init.py - Pyodide Initialization
Location: src/pyodide/python/pyodide_init.py
This script is the main entry point for the Python environment within the Pyodide worker. It is responsible for importing all necessary Python modules and making their functions available in the global namespace so they can be called from JavaScript.
Core Logic
This script performs the following actions:
- Imports Modules: It imports all the necessary functions from the other Python files in the same directory:
capture_system.pycode_transformation.pypyodide_utilities.py
- Exposes Functions: It attaches these functions to the
builtinsmodule, which makes them globally accessible in the Python environment. This allows JavaScript to call them viapyodide.runPython(). - Initializes Capture System: It calls
reset_captures()to ensure that thestdoutandstderrstreams are redirected and ready to capture output from the very beginning.