From f16f9174607b43b1911f2b0c3a8117b4f7ce7414 Mon Sep 17 00:00:00 2001 From: webreflection Date: Fri, 4 Oct 2024 17:28:43 +0200 Subject: [PATCH 1/3] Added donkey export decription --- docs/api.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/api.md b/docs/api.md index 6e4c71a..5e81afd 100644 --- a/docs/api.md +++ b/docs/api.md @@ -417,6 +417,33 @@ store = await storage("my-data-store", storage_class=MyStorage) # The store object is now an instance of MyStorage. ``` +### `@pyscript/core/donkey` + +Meant as *JS* related imports, you can `import { donkey } from '@pyscript/core/dist/core.js'` and automatically have both *pyscript* module running on your page and a utility to bootstrap a terminal based worker that could evaluate any Python code you need to. + +```js title="A donkey worker" +import { donkey } from '@pyscript/core/dist/core.js'; + +const { + process, // process(code) directly (code visible on the terminal) + execute, // execute(statement) in Python exec way + evaluate, // evaluate(expression) in Python eval way + clear, // clear() the terminal + reset, // reset() the terminal (including colors) + kill, // kill() the worker forever +} = donkey({ + type: 'py' || 'mpy', // the donkey interpreter to run + persistent: false, // use `true` to track globals and locals + terminal: '', // optionally set a target terminal container + config: {}, // the worker config (packages, files, etc.) +}); +``` + +About the **terminal** option, please note by default *PyScript* would create a target for that, so that if you don't want it visible on your page you can point to a *CSS* addressable container that is not visible (that is: a `#target` element that has a `display: none` as *CSS* property). + +With this primitive, and without even bothering with specialized *PyScript* tags, we hope anyone can try out of the box what is that *PyScript* enables on the Web! + + ### `@pyscript/core/dist/storage.js` The equivalent functionality based on the *JS* module can be found through our module. From 5cd6cebc1928c010495f56fe4ac35ad721c36f3a Mon Sep 17 00:00:00 2001 From: "Nicholas H.Tollervey" Date: Mon, 7 Oct 2024 11:55:06 +0100 Subject: [PATCH 2/3] Copy edit. --- docs/api.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/api.md b/docs/api.md index 5e81afd..e5dceb3 100644 --- a/docs/api.md +++ b/docs/api.md @@ -419,30 +419,39 @@ store = await storage("my-data-store", storage_class=MyStorage) ### `@pyscript/core/donkey` -Meant as *JS* related imports, you can `import { donkey } from '@pyscript/core/dist/core.js'` and automatically have both *pyscript* module running on your page and a utility to bootstrap a terminal based worker that could evaluate any Python code you need to. +Sometimes you need a Python worker ready and waiting to evaluate any code on +your behalf. This is the concept behind the JavaScript "donkey". We couldn't +think of a better way than "donkey" to describe something that is easy to +understand and shoulders the burden without complaint. This feature +means you're able to use PyScript without resorting to specialised +` + + @@ -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 871ec72..44b8f66 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 e0d05bd..493af3a 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.9.2/core.js"; +import { hooks } from "https://pyscript.net/releases/2024.10.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.9.2/core.js"; +import { hooks } from "https://pyscript.net/releases/2024.10.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.9.2/core.js"; +import { hooks } from "https://pyscript.net/releases/2024.10.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 a0867df..1c15121 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "2024.9.2" + "version": "2024.10.1" }