TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.85k stars 214 forks source link

Help with running online editor with server compilation #828

Closed straaljager closed 1 year ago

straaljager commented 2 years ago

I would like to create an online computer graphics course with Python, where users can write code in the browser, have it compiled to Javascript by a server and see the results on a canvas (very similar to the Transcrypt Turtle demo: http://www.transcrypt.org/live/turtle_site/turtle_site.html).

I'm struggling with setting up a local server to run the Transcrypt compilation and serve the results back to the browser. I could not find anything on this topic in the docs. Is there a minimal example somewhere on how to achieve this?

JennaSys commented 2 years ago

What follows is a bit of a guess, but I believe that using Transcrypt is going to require persisting the Python code locally, running Transcrypt as an external process (perhaps with the Python subprocess module), and then sending the generated JS code back to the client.

Looking at the live turtle site, there is a URL route (http://www.transcrypt.org/compile) that accepts Python code in a POST request and then returns the name of a generated JS file that can then be loaded into the browser. If you were to dig around, you would find that the Python code is persisted to http://www.transcrypt.org/live/user/ then the JS file generated by Transcrypt is sent back to the client from http://www.transcrypt.org/live/user/__target__/

What is happening on the server is an automated way of running Transcrypt just as you would from a command line once the Python code is persisted locally.

straaljager commented 2 years ago

Thanks a lot @JennaSys. That really helped my understanding of the client-server process. I will try to replicate this behaviour on a local machine.

JennaSys commented 1 year ago

Closing since no further comments.