From ccfdec62cfb46335ffbc29f3bf7cc11b7a478fda Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 22 Jan 2026 23:36:03 +0000 Subject: [PATCH] fix(web-client): ensure pyodide_io_patch.py is loaded and executed in python worker This commit ensures that `pyodide_io_patch.py` is correctly fetched and written to the Pyodide filesystem, and then executed to patch `pylabrobot.io` and inject global shims. This is necessary for direct hardware control in the browser (e.g. GitHub Pages). Also cleaned up a duplicate method definition in `web_serial_shim.py`. --- .../src/app/core/workers/python.worker.ts | 16 +++++++++++++++- .../src/assets/shims/web_serial_shim.py | 3 --- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/praxis/web-client/src/app/core/workers/python.worker.ts b/praxis/web-client/src/app/core/workers/python.worker.ts index ab37135f..74aec684 100644 --- a/praxis/web-client/src/app/core/workers/python.worker.ts +++ b/praxis/web-client/src/app/core/workers/python.worker.ts @@ -285,7 +285,8 @@ async function initializePyodide(id?: string) { { file: 'web_serial_shim.py', name: 'WebSerial' }, { file: 'web_usb_shim.py', name: 'WebUSB' }, { file: 'web_ftdi_shim.py', name: 'WebFTDI' }, - { file: 'web_hid_shim.py', name: 'WebHID' } + { file: 'web_hid_shim.py', name: 'WebHID' }, + { file: 'pyodide_io_patch.py', name: 'PyodideIOPatch' } ]; for (const shim of shims) { @@ -303,6 +304,19 @@ async function initializePyodide(id?: string) { } } + // Execute IO Patching (must happen before other code uses PLR) + try { + await pyodide.runPythonAsync(` +try: + import pyodide_io_patch + print("Pyodide IO Patch imported successfully") +except Exception as e: + print(f"Failed to import Pyodide IO Patch: {e}") + `); + } catch (err) { + console.error('Error running IO patch:', err); + } + // Verify files exist try { const files = pyodide.FS.readdir('.'); diff --git a/praxis/web-client/src/assets/shims/web_serial_shim.py b/praxis/web-client/src/assets/shims/web_serial_shim.py index 24b241ae..f539beb6 100644 --- a/praxis/web-client/src/assets/shims/web_serial_shim.py +++ b/praxis/web-client/src/assets/shims/web_serial_shim.py @@ -630,9 +630,6 @@ async def write(self, data: bytes) -> int: except Exception as e: raise RuntimeError(f"Write failed: {e}") - async def read(self, num_bytes: int = 1) -> bytes: - """Read data from the serial port.""" - async def read(self, num_bytes: int = 1) -> bytes: """Read data from the serial port.""" # Bypass check for FTDI