browser: pyfun bundle, a Dom façade in the cookbook, and the Promise-to-Async note - #117
Merged
Conversation
…to-Async note (#111) pyfun bundle <entry> -o <dir> [--asset f]... [--page fragment.html] emits a static page: the compiled Python (one file or a project's tree), the assets, a loader that boots Pyodide from the CDN the playground pins and runs the entry with stdout/stderr on the page, and an index.html around them, so a program is a shareable link with no server. examples/interop/browser/ holds a typed Dom façade over Pyodide's js module (opaque Element/Event/Callback, create_proxy behind Dom.proxy) and a counter page as its consumer; the harness compile- checks it, since running it needs a browser. A JS promise is awaitable under Pyodide, so an extern over a JS async API is typed -> Async a and nothing had to be built for the bridge. README, DESIGN §6, the cookbook README and ROADMAP item 20 updated.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #111, the last of the fourth dogfooding session's nine issues (ROADMAP item 20).
pyfun bundleA static page that runs the program:
index.html, the compiled Python (onemain.py, or a project's whole.pytree), the assets, andpyfun-bundle.js, a module script that boots Pyodide from its CDN (the release the playground pins), stages the files into the in-browser file system, and runs the entry with stdout and stderr in two<pre>panes.--pageputs the program's own markup above them. A type error stops the bundle before anything is written. The program is then a shareable link with no server, which is how two players get a game whose interface is the browser.The
Domfaçade (cookbook)examples/interop/browser/dom.pyfunis the first real consumer of the "publish a façade, import many" axis:extern import js, opaqueElement/Event/Callback, instance-access externs for the methods (.replaceChildren(),.addEventListener()), and Pyodide'screate_proxybehindDom.proxy, so the lifetime detail lives in the façade, not the program.counter.pyfunis the consumer: a top-levellet mutthe click handler reassigns (aglobalin the emitted Python), and the handler is an ordinary one-parameter function that Python calls with the event, which is the calling convention #107 settled on. Emitted:The harness compile-checks the example as a project (
tests/project.rs); running it needs a browser.The
PromisetoAsyncbridgeNothing to build: a JS promise is awaitable under Pyodide, so an extern over a JS async API is typed
-> Async aand awaited withlet!like any other.DESIGN.md§6 ("Browser target") records all three pieces; README gets the CLI line, the cookbook README the row, ROADMAP item 20 is closed.Tests
tests/cli.rs: a project entry with an asset and a page fragment bundles to the expected files with the expected loader constants; a single file bundles asmain.py; a type error writes nothing.tests/project.rs: the browser example type-checks and lowers with the expected shapes.cargo test,cargo clippy --all-targetsandcargo fmt --checkare clean.