Skip to content

Commit 82e2c2d

Browse files
authored
Merge pull request #136 from pyscript/2024-8-2
Documentation for release 2024.8.2
2 parents ea0c9a0 + 8653cd1 commit 82e2c2d

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
lines changed

docs/api.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ Pyodide and MicroPython. It is closely modelled on the
197197
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) found
198198
in browsers with some important Pythonic differences.
199199

200-
The simple use case is to pass in a URL and `await` the response. Remember, in
201-
order to use `await` you must have the `async` attribute in the `script` tag
202-
that references your code. If this request is in a function, that function
203-
should also be defined as `async`.
200+
The simple use case is to pass in a URL and `await` the response. If this
201+
request is in a function, that function should also be defined as `async`.
204202

205203
```python title="A simple HTTP GET with pyscript.fetch"
206204
from pyscript import fetch
@@ -834,7 +832,7 @@ While over on the main thread, this fragment of MicroPython will be able to
834832
access the worker's `version` function via the `workers` reference:
835833

836834
```html
837-
<script type="mpy" async>
835+
<script type="mpy">
838836
from pyscript import workers
839837
840838
pyworker = await workers["py-version"]
@@ -853,7 +851,7 @@ Should you wish to await for all workers on the page at load time, it's
853851
possible to loop over matching elements in the document like this:
854852

855853
```html
856-
<script type="mpy" async>
854+
<script type="mpy">
857855
from pyscript import document, workers
858856
859857
for el in document.querySelectorAll("[type='py'][worker][name]"):
@@ -872,7 +870,7 @@ an asynchronous way to import packages that were not originally referenced in
872870
your configuration.
873871

874872
```html title="A pyscript.js_import example."
875-
<script type="py" async>
873+
<script type="py">
876874
from pyscript import js_import, window
877875
878876
escaper, = await js_import("https://esm.run/html-escaper")
@@ -899,7 +897,7 @@ asynchronous way to import packages that were not originally referenced in your
899897
configuration.
900898
901899
```html title="A pyscript.py_import example."
902-
<script type="py" async>
900+
<script type="py">
903901
from pyscript import py_import
904902
905903
matplotlib, regex, = await py_import("matplotlib", "regex")

docs/beginning-pyscript.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ module in the document's `<head>` tag:
117117
<meta charset="utf-8" />
118118
<meta name="viewport" content="width=device-width,initial-scale=1" />
119119
<title>🦜 Polyglot - Piratical PyScript</title>
120-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.1/core.css">
121-
<script type="module" src="https://pyscript.net/releases/2024.8.1/core.js"></script>
120+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
121+
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
122122
</head>
123123
<body>
124124

@@ -168,8 +168,8 @@ In the end, our HTML should look like this:
168168
<meta charset="utf-8" />
169169
<meta name="viewport" content="width=device-width,initial-scale=1" />
170170
<title>🦜 Polyglot - Piratical PyScript</title>
171-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.1/core.css">
172-
<script type="module" src="https://pyscript.net/releases/2024.8.1/core.js"></script>
171+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
172+
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
173173
</head>
174174
<body>
175175
<h1>Polyglot 🦜 💬 🇬🇧 ➡️ 🏴‍☠️</h1>

docs/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ Combined with our `pyscript.fetch` utility, it's also possible to store more
819819
complex data from the web.
820820

821821
```python title="Writing a binary file."
822-
# Assume an `async` attribute / execution.
822+
# Assume async execution.
823823
from pyscript import fetch, window
824824

825825
href = window.location.href

docs/user-guide/first-steps.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ CSS:
2020
<meta charset="UTF-8">
2121
<meta name="viewport" content="width=device-width,initial-scale=1.0">
2222
<!-- PyScript CSS -->
23-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.1/core.css">
23+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
2424
<!-- This script tag bootstraps PyScript -->
25-
<script type="module" src="https://pyscript.net/releases/2024.8.1/core.js"></script>
25+
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
2626
</head>
2727
<body>
2828
<!-- your code goes here... -->
@@ -75,8 +75,27 @@ attributes:
7575
JSON or a TOML file,
7676
`config='{"packages":["numpy"]}'` and `config="./config.json"` or
7777
`config="./config.toml"` are all valid.
78-
* `async` - your Python code can contain a
79-
[top level await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await).
78+
* `async` - set this flag to `"false"` so your code won't run within a
79+
[top level await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await)
80+
(the default behaviour).
81+
82+
83+
!!! warning
84+
85+
**This behaviour changed in version 2024.8.2.**
86+
87+
PyScript now uses a
88+
[top level await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await)
89+
by default.
90+
91+
You used to have to include the `async` flag to enable this. Now, instead,
92+
use `async="false"` to revert the behaviour back to the old default
93+
behaviour of synchronous evaluation.
94+
95+
We made this change because many folks were `await`-ing functions and
96+
missing or not realising the need for the (old) `async` attribute. Hence
97+
the flip in behaviour.
98+
8099
* `worker` - a flag to indicate your Python code is to be run on a
81100
[web worker](workers.md) instead of the "main thread" that looks after the user
82101
interface.

docs/user-guide/plugins.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ on a web worker, the exact same sequence of steps takes place:
4242
callback found in test frameworks.
4343

4444
PyScript's interpreters can run their code either *synchronously* or
45-
*asynchronously*. No matter, the very same sequence is guaranteed to run in
46-
order in both cases, the only difference being the naming convention used to
47-
reference synchronous or asynchronous lifecycle hooks.
45+
*asynchronously* (**note**, the default is asynchronously). No matter, the very
46+
same sequence is guaranteed to run in order in both cases, the only difference
47+
being the naming convention used to reference synchronous or asynchronous
48+
lifecycle hooks.
4849

4950
### Hooks
5051

@@ -99,7 +100,7 @@ For example, this will work because all references are contained within the
99100
registered function:
100101

101102
```js
102-
import { hooks } from "https://pyscript.net/releases/2024.8.1/core.js";
103+
import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js";
103104

104105
hooks.worker.onReady.add(() => {
105106
// NOT suggested, just an example!
@@ -113,7 +114,7 @@ hooks.worker.onReady.add(() => {
113114
However, due to the outer reference to the variable `i`, this will fail:
114115

115116
```js
116-
import { hooks } from "https://pyscript.net/releases/2024.8.1/core.js";
117+
import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js";
117118

118119
// NO NO NO NO NO! ☠️
119120
let i = 0;
@@ -146,7 +147,7 @@ the page.
146147

147148
```js title="log.js - a plugin that simply logs to the console."
148149
// import the hooks from PyScript first...
149-
import { hooks } from "https://pyscript.net/releases/2024.8.1/core.js";
150+
import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js";
150151

151152
// The `hooks.main` attribute defines plugins that run on the main thread.
152153
hooks.main.onReady.add((wrap, element) => {
@@ -196,8 +197,8 @@ hooks.worker.onAfterRun.add(() => {
196197
<!-- JS plugins should be available before PyScript bootstraps -->
197198
<script type="module" src="./log.js"></script>
198199
<!-- PyScript -->
199-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.1/core.css">
200-
<script type="module" src="https://pyscript.net/releases/2024.8.1/core.js"></script>
200+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
201+
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
201202
</head>
202203
<body>
203204
<script type="mpy">

docs/user-guide/workers.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,11 @@ Here's how:
282282
<meta charset="utf-8">
283283
<meta name="viewport" content="width=device-width,initial-scale=1">
284284
<!-- PyScript CSS -->
285-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.1/core.css">
285+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
286286
<!-- This script tag bootstraps PyScript -->
287-
<script type="module" src="https://pyscript.net/releases/2024.8.1/core.js"></script>
287+
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
288288
<title>PyWorker - mpy bootstrapping pyodide example</title>
289-
<!-- the async attribute is useful but not mandatory -->
290-
<script type="mpy" src="main.py" async></script>
289+
<script type="mpy" src="main.py"></script>
291290
</head>
292291
</html>
293292
```

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "2024.8.1"
2+
"version": "2024.8.2"
33
}

0 commit comments

Comments
 (0)