From cfdd81dd43cebff1d891dc29258a381e9829ee42 Mon Sep 17 00:00:00 2001 From: webreflection Date: Fri, 13 Sep 2024 11:27:37 +0200 Subject: [PATCH 1/5] Add m/py:progress events description --- docs/api.md | 92 ++++++++++++++++++++++++++--------------------------- docs/faq.md | 16 ++++++++++ 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/docs/api.md b/docs/api.md index b12953d..4644dd3 100644 --- a/docs/api.md +++ b/docs/api.md @@ -766,6 +766,52 @@ The following code demonstrates a `pyscript.WebSocket` in action. ws = WebSocket(url="ws://example.com/socket", onmessage=onmessage) ``` +### `pyscript.js_import` + +If a JavaScript module is only needed under certain circumstances, we provide +an asynchronous way to import packages that were not originally referenced in +your configuration. + +```html title="A pyscript.js_import example." + +``` + +The `py_import` call returns an asynchronous tuple containing the Python +modules provided by the packages referenced as string arguments. + ## Main-thread only features ### `pyscript.PyWorker` @@ -863,52 +909,6 @@ for el in document.querySelectorAll("[type='py'][worker][name]"): ## Worker only features -### `pyscript.js_import` - -If a JavaScript module is only needed under certain circumstances, we provide -an asynchronous way to import packages that were not originally referenced in -your configuration. - -```html title="A pyscript.js_import example." - -``` - -The `py_import` call returns an asynchronous tuple containing the Python -modules provided by the packages referenced as string arguments. - ### `pyscript.sync` A function used to pass serializable data from workers to the main thread. diff --git a/docs/faq.md b/docs/faq.md index 23c25af..7b78a72 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -682,6 +682,22 @@ done"` message is written to the browser's console. ``` +#### m/py:progress + +The `py:progress` or `mpy:progress` event triggers on the main thread *during* interpreter bootstrap, being this either on *main* or *worker*. + +Following previous work around progress events from *micropip*, the received `event.detail` will be a string that confine operations between `Loading {what}` and `Loaded {what}`, where the first event would hence be `Loading Pyodide` and the last one per each bootstrap would be `Loaded Pyodide`. + +In between all operations will be forwarded as `event.detail`, such as: + + * `Loading files` and `Loaded files`, when `[files]` is found in the optional config + * `Loading fetch` and `Loaded fetch`, when `[fetch]` is found in the optional config + * `Loading JS modules` and `Loaded JS modules`, when `[js_modules.main]` or `[js_modules.worker]` +is found in the optional config + * finally, all optional packages handled via *micropip* or *mip* will also trigger various `Loading ...` and `Loaded ...` events so that users can actually see what is going on while the *app* is bootstrapping + +An example of this listener applied to a dialog cna be found in here: https://agiammarchi.pyscriptapps.com/kmeans-in-panel-copy/v1/ + ### Packaging pointers Applications need third party packages and [PyScript can be configured to From 7f57512a37601a76b7bb810740641430503e4250 Mon Sep 17 00:00:00 2001 From: webreflection Date: Fri, 13 Sep 2024 11:38:33 +0200 Subject: [PATCH 2/5] I took a chance to update some other part of the docs too --- docs/user-guide/offline.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/user-guide/offline.md b/docs/user-guide/offline.md index 9bf7717..919f387 100644 --- a/docs/user-guide/offline.md +++ b/docs/user-guide/offline.md @@ -40,7 +40,7 @@ cd pyscript-offline Build PyScript core by cloning the project repository and follow the instructions in our [developer guide](../developers.md) -Once completed, copy the `build` folder, that was been created by the build +Once completed, copy the `dist` folder, that has been created by the build step, into your `pyscript-offline` folder. ### PyScript core from `npm` @@ -114,7 +114,7 @@ python3 -m http.server -d ./public/ If you would like to test `worker` features, try instead: ```sh -npx static-handler --coi ./public/ +npx mini-coi ./public/ ``` ## Download a local interpreter @@ -231,7 +231,7 @@ Finally, we need the ability to install Python packages from a local source when using Pyodide. Put simply, we use the packages bundle from -[pyodide releases](https://github.com/pyodide/pyodide/releases/tag/0.24.1). +[pyodide releases](https://github.com/pyodide/pyodide/releases/tag/0.26.2). !!! warning @@ -240,8 +240,8 @@ Put simply, we use the packages bundle from It contains each package that is required by Pyodide, and Pyodide will only load packages when needed. -Once downloaded and extracted (we're using version `0.24.1` in this example), -we can simply copy the files and folders inside the `pyodide-0.24.1/pyodide/*` +Once downloaded and extracted (we're using version `0.26.2` in this example), +we can simply copy the files and folders inside the `pyodide-0.26.2/pyodide/*` directory into our `./public/pyodide/*` folder. Feel free to either skip or replace the content, or even directly move the From fc1efb60f7f89021d6d4d0d3dc5d3dd9d4ac3bb9 Mon Sep 17 00:00:00 2001 From: webreflection Date: Fri, 13 Sep 2024 12:08:26 +0200 Subject: [PATCH 3/5] Added JS storage too --- docs/api.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api.md b/docs/api.md index 4644dd3..cec8145 100644 --- a/docs/api.md +++ b/docs/api.md @@ -409,6 +409,12 @@ store = await storage("my-data-store", storage_class=MyStorage) # The store object is now an instance of MyStorage. ``` +### `@pyscript/core/dist/storage.js` + +The equivalent functionality based on the *JS* module can be found through our module. + +The goal is to be able to share the same database across different worlds (interpreters) and the functionality is nearly identical except there is no *class* to provide because the storage in *JS* is just a dictionary proxy that synchronizes behind the scene all read, write or delete operations. + ### `pyscript.web` The classes and references in this namespace provide a Pythonic way to interact From ae2fafa6ba888f010652d66913b766c67a83154c Mon Sep 17 00:00:00 2001 From: "Nicholas H.Tollervey" Date: Fri, 13 Sep 2024 11:11:23 +0100 Subject: [PATCH 4/5] Minor edits. --- docs/faq.md | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 7b78a72..0cf9b8a 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -684,19 +684,28 @@ done"` message is written to the browser's console. #### m/py:progress -The `py:progress` or `mpy:progress` event triggers on the main thread *during* interpreter bootstrap, being this either on *main* or *worker*. - -Following previous work around progress events from *micropip*, the received `event.detail` will be a string that confine operations between `Loading {what}` and `Loaded {what}`, where the first event would hence be `Loading Pyodide` and the last one per each bootstrap would be `Loaded Pyodide`. - -In between all operations will be forwarded as `event.detail`, such as: - - * `Loading files` and `Loaded files`, when `[files]` is found in the optional config - * `Loading fetch` and `Loaded fetch`, when `[fetch]` is found in the optional config - * `Loading JS modules` and `Loaded JS modules`, when `[js_modules.main]` or `[js_modules.worker]` -is found in the optional config - * finally, all optional packages handled via *micropip* or *mip* will also trigger various `Loading ...` and `Loaded ...` events so that users can actually see what is going on while the *app* is bootstrapping - -An example of this listener applied to a dialog cna be found in here: https://agiammarchi.pyscriptapps.com/kmeans-in-panel-copy/v1/ +The `py:progress` or `mpy:progress` event triggers on the main thread *during* +interpreter bootstrap (no matter if your code is running on main or in a +worker). + +The received `event.detail` is a string that indicates operations between +`Loading {what}` and `Loaded {what}`. So, the first event would be, for +example, `Loading Pyodide` and the last one per each bootstrap would be +`Loaded Pyodide`. + +In between all operations are `event.detail`s, such as: + + * `Loading files` and `Loaded files`, when `[files]` is found in the optional + config + * `Loading fetch` and `Loaded fetch`, when `[fetch]` is found in the optional + config + * `Loading JS modules` and `Loaded JS modules`, when `[js_modules.main]` or + `[js_modules.worker]` is found in the optional config + * finally, all optional packages handled via *micropip* or *mip* will also + trigger various `Loading ...` and `Loaded ...` events so that users can see + what is going on while PyScript is bootstrapping + +An example of this listener applied to a dialog can be [found in here](https://agiammarchi.pyscriptapps.com/kmeans-in-panel-copy/v1/). ### Packaging pointers From 9a75798d2c21e3b38535476ae2414144b7e0828f Mon Sep 17 00:00:00 2001 From: "Nicholas H.Tollervey" Date: Fri, 13 Sep 2024 13:53:09 +0100 Subject: [PATCH 5/5] Bump version --- docs/beginning-pyscript.md | 8 ++++---- docs/user-guide/first-steps.md | 4 ++-- docs/user-guide/plugins.md | 10 +++++----- docs/user-guide/workers.md | 4 ++-- version.json | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/beginning-pyscript.md b/docs/beginning-pyscript.md index 12a7717..998b53d 100644 --- a/docs/beginning-pyscript.md +++ b/docs/beginning-pyscript.md @@ -117,8 +117,8 @@ module in the document's `` tag: 🦜 Polyglot - Piratical PyScript - - + + @@ -168,8 +168,8 @@ In the end, our HTML should look like this: 🦜 Polyglot - Piratical PyScript - - + +

Polyglot 🦜 💬 🇬🇧 ➡️ 🏴‍☠️

diff --git a/docs/user-guide/first-steps.md b/docs/user-guide/first-steps.md index b13ba18..d8a6444 100644 --- a/docs/user-guide/first-steps.md +++ b/docs/user-guide/first-steps.md @@ -20,9 +20,9 @@ CSS: - + - + diff --git a/docs/user-guide/plugins.md b/docs/user-guide/plugins.md index 9c43cb1..bf776c6 100644 --- a/docs/user-guide/plugins.md +++ b/docs/user-guide/plugins.md @@ -100,7 +100,7 @@ For example, this will work because all references are contained within the registered function: ```js -import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js"; +import { hooks } from "https://pyscript.net/releases/2024.9.1/core.js"; hooks.worker.onReady.add(() => { // NOT suggested, just an example! @@ -114,7 +114,7 @@ hooks.worker.onReady.add(() => { However, due to the outer reference to the variable `i`, this will fail: ```js -import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js"; +import { hooks } from "https://pyscript.net/releases/2024.9.1/core.js"; // NO NO NO NO NO! ☠️ let i = 0; @@ -147,7 +147,7 @@ the page. ```js title="log.js - a plugin that simply logs to the console." // import the hooks from PyScript first... -import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js"; +import { hooks } from "https://pyscript.net/releases/2024.9.1/core.js"; // The `hooks.main` attribute defines plugins that run on the main thread. hooks.main.onReady.add((wrap, element) => { @@ -197,8 +197,8 @@ hooks.worker.onAfterRun.add(() => { - - + + + PyWorker - mpy bootstrapping pyodide example diff --git a/version.json b/version.json index f0baa93..f2ada48 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "2024.8.2" + "version": "2024.9.1" }