Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
aa09f15
Create draft PR for #936
create-issue-branch[bot] Feb 27, 2024
8814cae
default to pyodide and switch to skulpt if needed
loiswells97 Feb 27, 2024
1f0e5d0
attempt to parse imports in the runnerfactory
loiswells97 Feb 27, 2024
12bdce4
refactoring
loiswells97 Feb 28, 2024
f0ba6c3
tidying for linter
loiswells97 Feb 28, 2024
825961e
tidying to clarify approach in pr
loiswells97 Feb 28, 2024
e4354ed
refactoring to fix things
loiswells97 Feb 28, 2024
534871c
tidying
loiswells97 Feb 28, 2024
fb17e4d
tidying
loiswells97 Feb 29, 2024
7a3a74c
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Feb 29, 2024
e69126c
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Feb 29, 2024
edabb66
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Feb 29, 2024
ff0587f
fixing shikm assets
loiswells97 Apr 4, 2024
73ae099
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Apr 4, 2024
beaad38
initial attempt at explaining incompatible modules
loiswells97 Apr 4, 2024
901cd1d
Fixing snapshot and skulptrunner tests
loiswells97 Apr 4, 2024
88ce726
fixing pyodiderunner tests
loiswells97 Apr 4, 2024
ea622af
fixing py5 imported mode
loiswells97 Apr 4, 2024
95b85ab
fixing cypress tests
loiswells97 Apr 4, 2024
ef868e0
updating snapshot
loiswells97 Apr 4, 2024
f9d8b67
fixing linting warning
loiswells97 Apr 5, 2024
610f6ad
updating changelog
loiswells97 Apr 5, 2024
e399def
fixing the input function
loiswells97 Apr 5, 2024
797a559
trying to fix cypress
loiswells97 Apr 5, 2024
691f9fb
patching pygal tooltip formatter
loiswells97 Apr 8, 2024
b1683fe
couple of regex patches to eliminate some edge cases
loiswells97 Apr 8, 2024
f76ea51
tidying
loiswells97 Apr 8, 2024
fdc914d
moving pyodiderunner back for now to avoid conflicts
loiswells97 Apr 8, 2024
52c4067
Merge branch 'main' into issues/936-Spike_Investigate_using_pyodide_d…
loiswells97 Apr 8, 2024
1b82f42
tidying
loiswells97 Apr 8, 2024
68d85dc
changing and fixing tests
loiswells97 Apr 9, 2024
41594e6
fixing more tests
loiswells97 Apr 9, 2024
a571b06
fix mission zero tests
loiswells97 Apr 9, 2024
ce79754
testing pythonrunner switching which runner is active
loiswells97 Apr 9, 2024
70d1eea
updating snapshot
loiswells97 Apr 9, 2024
e53a055
tweaking and testing skulpt and pyodide runner visibilities
loiswells97 Apr 9, 2024
868ab31
tweaking incompatibility error message explanation
loiswells97 Apr 9, 2024
d2fcfc3
fix one of the mission zero cypress tests
loiswells97 Apr 10, 2024
a73fcad
update error explanation copy
loiswells97 Apr 10, 2024
bdb30a1
switching turtle to skulpt and forcing skulpt if sense hat always ena…
loiswells97 Apr 10, 2024
5d43c1a
update error explanation to include turtle
loiswells97 Apr 10, 2024
8e8bdc9
updating snapshot
loiswells97 Apr 10, 2024
e45e8e3
switching mission zero cypress port
loiswells97 Apr 10, 2024
d9b38f3
Merge branch 'pyodide-migration' into issues/936-Spike_Investigate_us…
sra405 Apr 29, 2024
73981ea
Merge pull request #937 from RaspberryPiFoundation/issues/936-Spike_I…
sra405 May 31, 2024
410b3d2
Merge branch 'main' into pyodide-migration
sra405 May 31, 2024
d93fd44
renaming and moving files temporarily to try and simplify the merge c…
loiswells97 Oct 1, 2024
8512211
Merge branch 'main' into pyodide-migration
loiswells97 Oct 1, 2024
09a9c60
reverting and fixing a few things post merge
loiswells97 Oct 1, 2024
cf403ca
some test fixing
loiswells97 Oct 1, 2024
3a50dc3
trying to fix cypress tests
loiswells97 Oct 3, 2024
34fed91
remove lingering only from cypress tests
loiswells97 Oct 3, 2024
efd0544
be more defensive looping over project components
loiswells97 Oct 3, 2024
19be64a
Matplotlib support (#1087)
loiswells97 Oct 8, 2024
17dfe0a
Fix dynamic pyodide switching with multiple files (#1097)
create-issue-branch[bot] Oct 9, 2024
41ef481
Web component pyodide support (#1090)
loiswells97 Oct 10, 2024
e582b65
Bump pyodide to latest version (#1098)
create-issue-branch[bot] Oct 11, 2024
b32205f
Webpack v5 bump (#1096)
loiswells97 Oct 15, 2024
8aba9c6
wip: initial seaborn support
loiswells97 Oct 15, 2024
be33227
Merge branch 'main' into seaborn-support
loiswells97 Oct 18, 2024
4c7e0b1
regenerating yarn.lock after merge conflict
loiswells97 Oct 18, 2024
f24db62
tidying commented out code
loiswells97 Oct 18, 2024
deaf01d
patching the urllib and requests
loiswells97 Oct 18, 2024
ef83226
refactoring to not show empty plot
loiswells97 Oct 18, 2024
55fa774
Delete public/_internal_sense_hat.js
loiswells97 Oct 18, 2024
43b08b3
Delete public/pygal.js
loiswells97 Oct 18, 2024
8dbf856
Update PythonRunner.jsx
loiswells97 Oct 18, 2024
f6461e1
fixing eslint
loiswells97 Oct 18, 2024
aca3e0c
adding a couple of tests
loiswells97 Oct 18, 2024
b4efcf3
fixing cypress test
loiswells97 Oct 21, 2024
07db2f7
tidying
loiswells97 Oct 21, 2024
d49fa07
adding cypress test for urllib to check the request patch
loiswells97 Oct 21, 2024
45c1c1d
upping the time for te seaborn test to try and get it passing on ci
loiswells97 Oct 21, 2024
bbb3097
updating changelog
loiswells97 Oct 21, 2024
7d18198
Merge branch 'main' into seaborn-support
loiswells97 Oct 21, 2024
dc85885
Merge branch 'main' into seaborn-support
loiswells97 Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- `Pyodide` `matplotlib` support (#1087)
- Tests for running simple programs in `pyodide` and `skulpt` (#1100)
- Fall back to `skulpt` if the host is not `crossOriginIsolated` (#1107)
- `Pyodide` `seaborn` support (#1106)

### Changed

Expand All @@ -26,9 +27,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Fixed

- Build to include public files (#1112)
- Dynamic runner switching with more than one `python` file (#1097)
- Pyodide running the correct file (`main.py`) when there are multiple `python` files (#1097)
- Build to include public files (#1112)
- Persisting choice of tabbed/split view when running `python` code (#1114)

## [0.27.1] - 2024-10-01
Expand Down
23 changes: 23 additions & 0 deletions cypress/e2e/spec-wc-pyodide.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ describe("Running the code with pyodide", () => {
.should("be.visible");
});

it("runs a simple seaborn program", () => {
runCode("import seaborn as sns\ndata = [50, 30, 100]\nsns.displot(data)");
cy.wait(12000);
cy.get("editor-wc")
.shadow()
.find(".pyodiderunner")
.find("img")
.should("be.visible");
});

it("runs a simple urllib program", () => {
cy.intercept("GET", "https://www.my-amazing-website.com", {
statusCode: 200,
});
runCode(
"import urllib.request\nresponse = urllib.request.urlopen('https://www.my-amazing-website.com')\nprint(response.getcode())",
);
cy.get("editor-wc")
.shadow()
.find(".pythonrunner-console-output-line")
.should("contain", "200");
});

it("runs a simple program with a module from PyPI", () => {
runCode(
"from strsimpy.levenshtein import Levenshtein\nlevenshtein = Levenshtein()\nprint(levenshtein.distance('hello', 'world'))",
Expand Down
63 changes: 59 additions & 4 deletions src/PyodideWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ const PyodideWorker = () => {

const runPython = async (python) => {
stopped = false;
await pyodide.loadPackage("pyodide_http");

await pyodide.runPythonAsync(`
import pyodide_http
pyodide_http.patch_all()

old_input = input

def patched_input(prompt=False):
Expand Down Expand Up @@ -249,19 +254,69 @@ const PyodideWorker = () => {
pyodidePackage = pyodide.pyimport("matplotlib");
} catch (_) {}
if (pyodidePackage) {
pyodide.runPython(`
import matplotlib.pyplot as plt
import io
import basthon

def show_chart():
bytes_io = io.BytesIO()
plt.savefig(bytes_io, format='jpg')
bytes_io.seek(0)
basthon.kernel.display_event({ "display_type": "matplotlib", "content": bytes_io.read() })
plt.show = show_chart
`);
return;
}
},
after: () => {},
},
seaborn: {
before: async () => {
pyodide.registerJsModule("basthon", fakeBasthonPackage);
// Patch the document object to prevent matplotlib from trying to render. Since we are running in a web worker,
// the document object is not available. We will instead capture the image and send it back to the main thread.
pyodide.runPython(`
import js

class DummyDocument:
def __init__(self, *args, **kwargs) -> None:
return
def __getattr__(self, __name: str):
return DummyDocument
js.document = DummyDocument()
`);

// Ensure micropip is loaded which can fetch packages from PyPi.
// See: https://pyodide.org/en/stable/usage/loading-packages.html
if (!pyodide.micropip) {
await pyodide.loadPackage("micropip");
pyodide.micropip = pyodide.pyimport("micropip");
}

// If the import is for a PyPi package then load it.
// Otherwise, don't error now so that we get an error later from Python.
await pyodide.micropip.install("seaborn").catch(() => {});
},
after: () => {
pyodide.runPython(`
import matplotlib.pyplot as plt
import io
import basthon

bytes_io = io.BytesIO()
plt.savefig(bytes_io, format='jpg')
bytes_io.seek(0)
basthon.kernel.display_event({ "display_type": "matplotlib", "content": bytes_io.read() })
def is_plot_empty():
fig = plt.gcf()
for ax in fig.get_axes():
# Check if the axes contain any lines, patches, collections, etc.
if ax.lines or ax.patches or ax.collections or ax.images or ax.texts:
return False
return True

if not is_plot_empty():
bytes_io = io.BytesIO()
plt.savefig(bytes_io, format='jpg')
bytes_io.seek(0)
basthon.kernel.display_event({ "display_type": "matplotlib", "content": bytes_io.read() })
`);
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ describe("PyodideWorker", () => {
);
});

test("it patches urllib and requests modules", async () => {
await worker.onmessage({
data: {
method: "runPython",
python: "print('hello')",
},
});
expect(pyodide.runPythonAsync).toHaveBeenCalledWith(
expect.stringMatching(/pyodide_http.patch_all()/),
);
});

test("it tries to load package from file system", async () => {
pyodide._api.pyodide_code.find_imports = () => new MockPythonArray("numpy");
await worker.onmessage({
Expand Down
Loading