mirror of
https://github.com/pyscript/pyscript.git
synced 2022-05-01 19:47:48 +03:00
Merge branch 'main' into pys-19/allow_out_err_redirect
This commit is contained in:
@@ -19,8 +19,8 @@ To try PyScript, import the pyscript to your html page with:
|
|||||||
```
|
```
|
||||||
At that point, you can then use PyScript components in your html page. PyScript currently implements the following elements:
|
At that point, you can then use PyScript components in your html page. PyScript currently implements the following elements:
|
||||||
|
|
||||||
* `<py-script>`: that can be used to define python code that is execute withing the web page. The element itself is not rendered to the page and only used to add logic
|
* `<py-script>`: that can be used to define python code that is executable within the web page. The element itself is not rendered to the page and only used to add logic
|
||||||
* `<py-repl>`: creates a REPL component that is rendered to the page as a code editor and allows users to right code that can be executed
|
* `<py-repl>`: creates a REPL component that is rendered to the page as a code editor and allows users to write code that can be executed
|
||||||
|
|
||||||
Check out the `/examples` folder for more examples on how to use it, all you need to do is open them in Chrome.
|
Check out the `/examples` folder for more examples on how to use it, all you need to do is open them in Chrome.
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ for (const d of data) {
|
|||||||
|
|
||||||
<py-script>
|
<py-script>
|
||||||
from pyodide import create_proxy, to_js
|
from pyodide import create_proxy, to_js
|
||||||
from esm import d3
|
import d3
|
||||||
|
|
||||||
fruits = [
|
fruits = [
|
||||||
dict(name="🍊", count=21),
|
dict(name="🍊", count=21),
|
||||||
|
|||||||
@@ -215,8 +215,6 @@ export class PyScript extends BaseEvalElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async _register_esm(pyodide: PyodideInterface): Promise<void> {
|
protected async _register_esm(pyodide: PyodideInterface): Promise<void> {
|
||||||
const imports: {[key: string]: unknown} = {}
|
|
||||||
|
|
||||||
for (const node of document.querySelectorAll("script[type='importmap']")) {
|
for (const node of document.querySelectorAll("script[type='importmap']")) {
|
||||||
const importmap = (() => {
|
const importmap = (() => {
|
||||||
try {
|
try {
|
||||||
@@ -233,17 +231,19 @@ export class PyScript extends BaseEvalElement {
|
|||||||
if (typeof name != "string" || typeof url != "string")
|
if (typeof name != "string" || typeof url != "string")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
let exports: object
|
||||||
try {
|
try {
|
||||||
// XXX: pyodide doesn't like Module(), failing with
|
// XXX: pyodide doesn't like Module(), failing with
|
||||||
// "can't read 'name' of undefined" at import time
|
// "can't read 'name' of undefined" at import time
|
||||||
imports[name] = {...await import(url)}
|
exports = {...await import(url)}
|
||||||
} catch {
|
} catch {
|
||||||
console.error(`failed to fetch '${url}' for '${name}'`)
|
console.warn(`failed to fetch '${url}' for '${name}'`)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pyodide.registerJsModule(name, exports)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pyodide.registerJsModule("esm", imports)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSourceFromElement(): string {
|
getSourceFromElement(): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user