Skip to content

Commit

Permalink
Upgrade to Pyodide 0.21.3 (#887)
Browse files Browse the repository at this point in the history
* Upgrade to Pyodide 21.3

* During the PyodideRuntime test, set the indexURL parameter of loadPyodide to allow Jest to find pyodide-adjacent files.
  • Loading branch information
JeffersGlass committed Oct 27, 2022
1 parent ab085c2 commit 4850f39
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 26 deletions.
16 changes: 8 additions & 8 deletions docs/tutorials/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ The `<py-config>` tag can be used as follows:
autoclose_loader = true

[[runtimes]]
src = "https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.js"
name = "pyodide-0.21.2"
src = "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js"
name = "pyodide-0.21.3"
lang = "python"
</py-config>
```
Expand All @@ -170,8 +170,8 @@ Alternatively, a JSON config can be passed using the `type` attribute.
{
"autoclose_loader": true,
"runtimes": [{
"src": "https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.js",
"name": "pyodide-0.21.2",
"src": "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js",
"name": "pyodide-0.21.3",
"lang": "python"
}]
}
Expand All @@ -189,8 +189,8 @@ where `custom.toml` contains
```
autoclose_loader = true
[[runtimes]]
src = "https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.js"
name = "pyodide-0.21.2"
src = "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js"
name = "pyodide-0.21.3"
lang = "python"
```

Expand All @@ -206,8 +206,8 @@ where `custom.json` contains
{
"autoclose_loader": true,
"runtimes": [{
"src": "https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.js",
"name": "pyodide-0.21.2",
"src": "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js",
"name": "pyodide-0.21.3",
"lang": "python"
}]
}
Expand Down
14 changes: 7 additions & 7 deletions pyscriptjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyscriptjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"jest": "29.1.2",
"jest-environment-jsdom": "29.1.2",
"prettier": "2.7.1",
"pyodide": "0.21.2",
"pyodide": "0.21.3",
"rollup": "2.79.1",
"rollup-plugin-copy": "3.4.0",
"rollup-plugin-css-only": "3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions pyscriptjs/src/pyconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const defaultConfig: AppConfig = {
"type": "app",
"autoclose_loader": true,
"runtimes": [{
"src": "https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.js",
"name": "pyodide-0.21.2",
"src": "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js",
"name": "pyodide-0.21.3",
"lang": "python"
}],
"packages":[],
Expand Down
2 changes: 1 addition & 1 deletion pyscriptjs/src/pyodide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class PyodideRuntime extends Runtime {

constructor(
config: AppConfig,
src = 'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.js',
src = 'https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js',
name = 'pyodide-default',
lang = 'python',
) {
Expand Down
6 changes: 3 additions & 3 deletions pyscriptjs/tests/integration/test_py_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_py_config_external(self):
)
assert self.console.log.lines[-1] == "config name: app with external config"

# The default pyodide version is 0.21.2 as of writing
# The default pyodide version is 0.21.3 as of writing
# this test which is newer than the one we are loading below
# (after downloading locally) -- which is 0.20.0

Expand Down Expand Up @@ -175,8 +175,8 @@ def test_multiple_runtimes(self):
{
"runtimes": [
{
"src": "https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.js",
"name": "pyodide-0.21.2",
"src": "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js",
"name": "pyodide-0.21.3",
"lang": "python"
},
{
Expand Down
16 changes: 12 additions & 4 deletions pyscriptjs/tests/unit/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@ describe('PyodideRuntime', () => {
/**
* Since import { loadPyodide } from 'pyodide';
* is not used inside `src/pyodide.ts`, the function
* `runtime.initialize();` below which calls
* `loadInterpreter` and thus `loadPyodide` results
* in an expected issue of:
* `runtime.loadInterpreter();` below which calls
* `loadPyodide()` results in an expected issue of:
* ReferenceError: loadPyodide is not defined
*
* To make jest happy, while also not importing
* explicitly inside `src/pyodide.ts`, the
* following lines - so as to dynamically import
* and make it available in the global namespace
* - are used.
*
* Pyodide uses a "really hacky" method to get the
* URL/Path where packages/package data are stored;
* it throws an error, catches it, and parses it. In
* Jest, this calculated path is different than in
* the browser/Node, so files cannot be found and the
* test fails. We set indexURL below the correct location
* to fix this.
* See https://github.com/pyodide/pyodide/blob/7dfee03a82c19069f714a09da386547aeefef242/src/js/pyodide.ts#L161-L179
*/
const pyodideSpec = await import('pyodide');
global.loadPyodide = pyodideSpec.loadPyodide;
global.loadPyodide = async (options) => pyodideSpec.loadPyodide(Object.assign({indexURL: '../pyscriptjs/node_modules/pyodide/'}, options));
await runtime.loadInterpreter();
});

Expand Down

0 comments on commit 4850f39

Please sign in to comment.