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

Add a Pyodide runner based on the python-execution-prototypes #893

Merged
merged 43 commits into from
Feb 13, 2024

Commits on Jan 28, 2024

  1. Configuration menu
    Copy the full SHA
    b6fe433 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    809e395 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    ea2080e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    73eb5b1 View commit details
    Browse the repository at this point in the history
  5. Set HTTP headers to enable SharedArrayBuffer for all requests

    Previously, I thought we needed to set these HTTP headers for the web
    worker to enable SharedArrayBuffer usage, but we actually need to set
    them for requests to the top-level web page. Therefore, ensure the
    crossorigin attribute is added to script/link tags for cross-origin
    resources.
    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    2469a80 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    0e220ad View commit details
    Browse the repository at this point in the history
  7. Update the changelog

    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    fffffd7 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    881a615 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    d4e1232 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    dd73d4d View commit details
    Browse the repository at this point in the history
  11. Move PyodideWorker.js into the PyodideRunner/ directory

    The worker and its dependencies (pygal / _internal_sense_hat) use ES6
    so we need to make sure this is transpiled as part of the standard
    webpack build so that it works with all browsers.
    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    bd73880 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    4f791e1 View commit details
    Browse the repository at this point in the history
  13. Fix eslint errors and warnings

    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    409ca2f View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    cab3c1d View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    6b6bd04 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    889de0f View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    69a7b80 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    03be18c View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    b5452c8 View commit details
    Browse the repository at this point in the history
  20. Write components to the Wasm in-memory filesystem before running prog…

    …rams
    
    https://pyodide.org/en/stable/usage/api/js-api.html#pyodide.FS
    
    In the future, we could open this up to support other file types
    (not just .py, .txt and .csv) and we could allow users to create files
    with Python and then save the result to a component in the project, e.g.
    to display an image of the Mandelbrot set.
    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    af3c012 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    7a33589 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    60dec34 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    504930b View commit details
    Browse the repository at this point in the history
  24. Implement visualOutput.handleVisual to display graphical output

    I originally tried implementing this with redux by dispatching an event
    containing the ‘content’ object but this isn’t always serialisable, e.g.
    for turtle it is a JavaScript Map object. Redux prints a warning if the
    object isn’t serialisable. Therefore, instead, use a channel pattern
    that allows the sub-component (VisualOutput) to subscribe to the
    handleVisual method calls and update its DOM.
    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    b6fa599 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    5ff50b7 View commit details
    Browse the repository at this point in the history
  26. Forward standard input to the PyodideWorker.js

    Most of this code was copied from PythonRunner.js and then adapted to
    implement the handleInput function and set the stdinBuffer array. See
    this commit for more information:
    
    RaspberryPiFoundation/python-execution-prototypes@42a7001
    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    394df9e View commit details
    Browse the repository at this point in the history
  27. Add support for stdin control keys

    Previously, if you ran the following program in the editor using Pyodide
    there was no way to cleanly exit:
    
    ```python
    import sys
    
    for line in sys.stdin:
        print(line)
    ```
    
    This wasn’t an issue before because Skulpt only supported the input()
    function which scans to the end of the line and does not look for EOF
    when the standard input is closed.
    
    To support this, add the ability to press control-d which sets the first
    element in the stdinBuffer to -1. This signals to the worker that stdin
    is closed, which it signals to Pyodide by returning 0 from read(buffer).
    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    7ccd8c9 View commit details
    Browse the repository at this point in the history
  28. Remove ctrl-c and ctrl-z handling in PyodudeRunner.jsx

    These keys are used for copying and undoing on Windows.
    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    3677a56 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    183e7c7 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    cf382fb View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    78c0784 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    ea6dec0 View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    e1276c2 View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    7ef9742 View commit details
    Browse the repository at this point in the history
  35. Dynamically show the VisualOutputPane when a visual program is run

    Previously, we had to manually add ?show_visual_output=true to the URL
    to show the pane. We now set showVisual to true when the first
    handleVisual message is received and use a ‘showing’ state variable on
    the visual objects to determine whether we have already rendered the
    visual to avoid re-renders.
    tuzz committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    4619aa5 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    64a8fe1 View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    18101cf View commit details
    Browse the repository at this point in the history

Commits on Jan 30, 2024

  1. Load PyodideWorker.mock.js in the Jest tests

    Jest doesn’t support Web Workers and was erroring because the
    importScripts function isn’t available. Best practice seems to be to
    mock the module and returned canned responses. Currently, we don’t have
    Jest tests for the experimental PyodideRunner.js so an empty
    implementation is sufficient but we could change this later.
    
    https://stackoverflow.com/questions/42567535#answer-62436219
    tuzz committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    ff594e0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a1bae39 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    35810c1 View commit details
    Browse the repository at this point in the history

Commits on Feb 12, 2024

  1. Configuration menu
    Copy the full SHA
    19dc454 View commit details
    Browse the repository at this point in the history
  2. Replace ternaries with && expressions

    These ternaries were copied over from PythonRunner.
    tuzz committed Feb 12, 2024
    Configuration menu
    Copy the full SHA
    a47452f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    2d6931a View commit details
    Browse the repository at this point in the history