Using the new Python 3.13 REPL with Emscripten

Sorry to follow up to an old thread here, but I actually spent a little bit of time poking at this yesterday. I made some progress but ultimately wasn’t able to get things working. I’m by no means an expert, but I think getting PyREPL to work with Emscripten is going to be a little tricky.

I did get a build working (kind of) with xterm-pty, which is cool because a lot of the code for managing i/o streams that exists in the current demo is just handled by xterm-pty directly. You can also change some stuff in the build configuration to make it build with readline (which gets rid of an error about a missing rlcompleter module), but the next problem is that, afaict, PyREPL strictly depends on ncurses, and I wasn’t able to figure out how to do an Emscripten build with ncurses. There seem to be some examples of building ncurses for Emscripten (e.g., this repo), but I’m just kind of poking at this stuff for the first time and so not sure how to make that work here.

If anyone has any pointers for how to build Python with curses support for Emscripten, that would be cool. If not, I might try to poke at this some more if I have time, but it’s not currently at the top of my priority list.

In case it’s of use, I put my current progress at: GitHub - adqm/cpython at wasm_repl_pty
There are still a bunch of issues with it, but maybe useful if you want to try to build on it. Here’s a build of the demo from that branch (note that it falls back to the basic REPL and doesn’t know what to do with arrow keys, presumably because of the missing curses library): https://hz.mit.edu/wasm_repl_demo_pty.zip
It also only seems to work in Chromium (not Firefox); I haven’t looked into that yet either.

In the meantime, I did also put in a PR that includes other improvements to the existing WASM REPL; if that’s somehow helpful, feel free to make use of any of that code.

Anyway, sorry to be responding without having an actual solution to your question; but just wanted to share some thoughts since I had been poking at this recently!

2 Likes