8000 support different pyodide versions by fpliger · Pull Request #328 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

support different pyodide versions #328

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

Merged
merged 11 commits into from
May 11, 2022
Prev Previous commit
Next Next commit
change runtimes from strings to objects
  • Loading branch information
fpliger committed May 11, 2022
commit a3771ea0bc5fb7822174747e2c89eb825ed3556c
5 changes: 4 additions & 1 deletion pyscriptjs/examples/simple_clock.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
<py-config>
8000 Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this pattern

- autoclose_loader: false
- runtimes:
- "https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js"
-
src: "https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js"
name: pyodide-0.20
lang: python
</py-config>
</head>

Expand Down
20 changes: 15 additions & 5 deletions pyscriptjs/src/components/pyconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ import { loadInterpreter } from '../interpreter';
import type { PyScript } from './pyscript';


const DEFAULT_RUNTIME = "https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js";
const DEFAULT_RUNTIME = {
src: "https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js",
name: "pyodide-default",
lang: "python"
}

export type Runtime = {
src: string;
name?: string;
lang?: string;
};

export type AppConfig = {
autoclose_loader: boolean;
name?: string;
version?: string;
runtimes?: Array<string>;
};
runtimes?: Array<Runtime>;
};

let appConfig_: AppConfig = {
autoclose_loader: true,
Expand Down Expand Up @@ -169,8 +179,8 @@ export class PyConfig extends BaseEvalElement {
console.log("Initializing runetimes...")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo? runetimes

for (const runtime of this.values.runtimes) {
const script = document.createElement("script"); // create a script DOM node
const runtimeSpec = new PyodideRuntime(runtime);
script.src = runtime; // set its src to the provided URL
const runtimeSpec = new PyodideRuntime(runtime.src);
script.src = runtime.src; // set its src to the provided URL
script.onload = () => {
runtimeSpec.initialize();
}
Expand Down
0