-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support "python mode" for the p5 package and support the py5 package #949
Labels
Milestone
Comments
High priority to refine and understand ticket details before Chris leaves |
tuzz
referenced
this issue
Feb 13, 2024
This pull request adds experimental support for running Python programs using Pyodide. The code is based on the [python-execution-prototypes](https://github.com/RaspberryPiFoundation/python-execution-prototypes) and the [technical analysis](https://docs.google.com/document/d/1mpKliJaqYYkPJR1hGLZxUDhNFOwgBm69nc70iiVj_3I/edit#heading=h.3orc9tdzyy4b) document. The related GitHub issue is #891. The PyodideRunner.jsx can be used instead of the current PythonRunner.jsx (Skulpt) by provided a `?pyodide=true` parameter in the URL as shown in the screenshot below: <img width="1439" alt="Screenshot 2024-01-30 at 11 39 01" src="https://github.com/RaspberryPiFoundation/editor-ui/assets/892251/a0185ec3-aaf5-40d4-a5e8-e9973fb1c98f"> ### Notes The PyodideRunner supports the following features: - Execution of Python programs - Importing of [most of](https://pyodide.org/en/stable/usage/wasm-constraints.html) Python's standard library - Importing of [many common](https://pyodide.org/en/stable/usage/packages-in-pyodide.html) Python packages - Importing of pure Python packages from PyPi - Stopping execution - Sending standard input to Python programs - Closing the standard input stream by pressing `Ctrl-d` - Visualising turtle graphics using the [modified turtle package](https://github.com/RaspberryPiFoundation/turtle) - Visualising pygal charts using the [modified pygal package](https://github.com/RaspberryPiFoundation/pygal.js) Due to time constraints, the following tasks remain outstanding: - Visualising sense_hat graphics using the [modified sense_hat package](https://github.com/RaspberryPiFoundation/sense_hat) - There is a work-in-progress pull request [here](#913) - Apply HTTP headers in a service worker (see #903) - Note that `crossorigin` will need to be added to cross-domain resources once the HTTP headers are added - Add unit/integration tests that run real Python programs through the PyodideRunner.jsx - Manual testing for backwards compatibility of existing Python programs, projects and the WebComponent - Implementing the p5 package to work with Pyodide - See https://github.com/RaspberryPiFoundation/python-execution-prototypes/issues/1 - Implementing a dedicated SQL editor for use in the Ada CS project - Note that Pyodide supports importing `sqlite3` so we can add a UI wrapper around it --------- Co-authored-by: Scott Adams <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The p5 package that the Pyodide prototype is using is based on the p5.js library. It uses names like
createCanvas
instead ofsize
which means that programs can't be copied to your local machine and run with the p5 package in CPython. The editor-ui shims are adapting the interface of the p5.js library (example) so we need to write equivalent adapters for p5 and also the py5 package which has a few additional modifications in the shim.While investigating this, I found this helpful video which explains the different Processing libraries and found this useful table that also contains a list with features and limitations of each. In short, we need to support "python mode" in a web context and the only implementation that supports that (from the table) is ProcessingJS which is used by Skulpt and Trinket but is no longer supported. The pyp5js project has a GitHub issue where someone attempted to translate between python mode and p5.js with Python but the code was only a proof of concept.
Therefore, I think we have two possible approaches:
Convert our p5 and py5 shims from Skulpt plugins to plain JavaScript files that export an object in that format that Pyodide's registerJsModule function expects. Then, instead of using the p5 package from the Basthon project, we could just register this module instead.
Convert our p5 and py5 shims from Skulpt plugins to Python packages that import p5.js and export the "python mode" interface we want. This might be more portable because it isn't Pyodide specific but is probably more effort because we need to adapt from the the shims written in JavaScript to the equivalent in Python.
The text was updated successfully, but these errors were encountered: