Skip to content
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

Enable a pyodide mode #124

Closed
berinhard opened this issue Jun 14, 2020 · 4 comments · Fixed by #133
Closed

Enable a pyodide mode #124

berinhard opened this issue Jun 14, 2020 · 4 comments · Fixed by #133

Comments

@berinhard
Copy link
Owner

This issue comes from the #123 proof of concept and it goals a full support of pyp5js with Pyodide.

The backend

  1. Use pyodide as the default "compiler" for pyp5js;
  2. Add a flag to the pyp5js new command to enable people to keep on using Transcrypt;
    2.1 This will probably result on a need of a "config" file for the sketch, something like Processing's sketch.properties. I think a JSON to hold this data would be good enough for now;
  3. Implement a way to "compile" the pyodide sketch;
  4. Update the monitor command to work with pyodide as well;
@berinhard
Copy link
Owner Author

One important thing to address is: why not improve @Luxapodular initial work? In my opinion the reasons are:

  1. pyp5js already has a working wrapper covering all of p5.js API which works with pyodide as well;
  2. pyp5js has a set of tools (web client and terminal CLI client) to facilitate people to manage their sketches and we can take advantage of that;

Anyway, I REALLY glad for @Luxapodular to opened up this world of possibilities with p5.js and Python with his code!!! Seriously, thanks a lot!

@berinhard
Copy link
Owner Author

I know there are some people in this issue interested in this discussion, so I invite you to take a loot in this demo I've released today:

https://berinhard.github.io/pyp5js/pyodide/

@casatir
Copy link

casatir commented Nov 25, 2020

Hi there,

Just to let you know that I managed to wrap p5.js for Basthon (which uses Pyodide under the hood). This notebook is an example but you can find more at the end of this gallery.

The code is here. I took a rather different approach that might be equivalent to yours at some point. Basically, it

  • gets all attributes names (functions + variables) from a dummy instance
  • exposes them to global scope for import *
  • wraps functions to keep a pointer to global instance
  • updates variables (int, str, float, ...) before each call to setup/draw.

This is all procedural and there is no global instance variable exposed to window. There is also an instance mode for running multiple sketches in parallel: example.

I would like to thank you for this nice work that was a good starting point for integrating p5.js in Basthon.

@berinhard
Copy link
Owner Author

@casatir thanks for your message! Your strategy is very interesting actually! It's way more pythonic than mine. Thanks for the reference and congrats for Basthon! It seems to be a cool project =)

tuzz added a commit to RaspberryPiFoundation/python-execution-prototypes that referenced this issue Jan 4, 2024
The p5 package from Basthon depends on a ‘basthon’ package. I’m not sure
if any of this is needed yet, so provide a fake implementation of that
package in the pyodide environment.

This GitHub comment led me in a useful direction:
berinhard/pyp5js#124 (comment)

kernel.display_event() is called from this file:
https://framagit.org/basthon/basthon-kernel/-/blob/master/packages/kernel-python3/src/modules/p5/p5/_core.py#L82-83

kernel.locals().get() and kernel.locals().keys() are called from this file:
https://framagit.org/basthon/basthon-kernel/-/blob/master/packages/kernel-python3/src/modules/p5/p5/_nsmanager.py#L25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants