You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`_demo.yml`| Hashes `compiler_lib.wasm` into `version.json` (cache-busting) and deploys `demo/` to Cloudflare Pages |
15
15
|`cli.yml`| Standalone (not part of the pipeline above): builds and tests `cli/`; on `main` pushes also publishes the release binary + `cli/setup/` scripts (`install.sh`, `uninstall.sh`) to GitHub Pages |
16
16
|`host.yml`| Standalone: deno-lints and tests each host capability (`dom`, `network`, `storage`, `time`) in headless Chromium; on `main` pushes also deploys their ESM sources to Cloudflare Pages (`edge-python-host`) |
17
-
|`std.yml`| Standalone: clippy + build + optimize + test each stdpkg wasm (`json`, `re`, `math`); on `main` pushes also deploys the per-package `.wasm` to Cloudflare Pages (`edge-python-std`) |
17
+
|`std.yml`| Standalone: clippy + build + optimize + test each stdpkg (`json`, `re`, `math` as wasm; `test` is pure Edge Python, so its steps skip the wasm build and only run the corpus); on `main` pushes also deploys the per-package `.wasm` to Cloudflare Pages (`edge-python-std`) |
Copy file name to clipboardExpand all lines: docs/reference/packages.md
+28-1Lines changed: 28 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,33 @@ print(factorial(5)) # 120
63
63
64
64
Integers are bounded by the VM's `i128`, so `factorial`, `comb`, `perm`, and `lcm` raise `ValueError` past that range, and there is no `complex` / `cmath`. Pre-built `.wasm` is served from `https://std.edgepython.com/math.wasm`. Full API: [`std/math/README.md`](https://github.com/dylan-sutton-chavez/edge-python/tree/main/std/math).
65
65
66
+
### `test`
67
+
68
+
A tiny unit-test harness written in pure Edge Python, not a Rust `.wasm` module: fixtures, test registration, exception assertions, and a runner that reports pass/fail and sets the exit code. It leans only on language built-ins (`assert`, `issubclass`, `SystemExit`), so it needs no host capability and runs wherever the VM runs.
69
+
70
+
```python
71
+
from test import fixture, test, raises, run
72
+
73
+
@fixture
74
+
defuser():
75
+
return {"name": "Ana"}
76
+
77
+
@test("user has a name", "user")
78
+
deftest_name(user):
79
+
assert user["name"] =="Ana"
80
+
81
+
@test("division by zero raises")
82
+
deftest_div():
83
+
with raises(ZeroDivisionError):
84
+
1/0
85
+
86
+
run() # prints PASS/FAIL lines and a summary, then raises SystemExit(0 if all passed, else 1)
87
+
```
88
+
89
+
`@fixture` registers a `def` under its name and injects it by keyword into the tests that ask for it; `@test(description, *uses)` registers a test plus the fixtures it pulls; `raises(ExcType)` is a context manager asserting the block raises `ExcType` (a subclass, or any type in a tuple); `run()` executes every registered test, prints `PASS` / `FAIL` / `ERROR` and a summary, then raises `SystemExit(1 if any failed, else 0)` so a host can read the result as a process exit code.
90
+
91
+
Unlike the other standard packages, `test` ships as **pure Edge Python source** (`src/entry.py`), not a compiled `.wasm`, so there is no `cargo` build and nothing served from `std.edgepython.com`; the browser runtime resolves it by default and imports the `.py` directly (see [Defaults](#defaults)). Full API: [`std/test/README.md`](https://github.com/dylan-sutton-chavez/edge-python/tree/main/std/test).
92
+
66
93
## Host libraries
67
94
68
95
Plain-JS capabilities that run on the browser's main thread, registered declaratively via the `host` field of [`packages.json`](/reference/imports#packages-json) (with the `<edge-python>` element), programmatically via `createWorker({ hostModules })`, or resolved by default with no config at all (see [Defaults](#defaults)). No `.wasm`, no Rust, no build step. Each call defers to the main thread over `postMessage` (around 0.1 to 0.4 ms); Python sees a synchronous call. The ESM loads lazily, the first time a run imports it.
@@ -143,7 +170,7 @@ One manifest drives both directions: `imports` for worker-side `.py` / `.wasm` m
143
170
144
171
### Defaults
145
172
146
-
The browser runtime ships a built-in base manifest, so the official packages resolve by bare name with **no `packages.json` at all**: the std `.wasm`packages (`json`, `re`, `math`) and the host libraries (`dom`, `network`, `storage`, `time`). Three rules:
173
+
The browser runtime ships a built-in base manifest, so the official packages resolve by bare name with **no `packages.json` at all**: the std packages (`json`, `re`, `math`, and the pure-Python `test`) and the host libraries (`dom`, `network`, `storage`, `time`). Three rules:
147
174
148
175
-**Lazy.** A default is fetched only when a run actually imports it. Unused defaults never hit the network.
149
176
-**Overridable.** Your `packages.json` (or `imports` / `hostModules`) wins for the same name, so you can pin a specific version or URL.
Copy file name to clipboardExpand all lines: std/README.md
+10-5Lines changed: 10 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
1
# Edge Python Standard Packages
2
2
3
-
Official `.wasm`standard-library packages for [Edge Python](https://edgepython.com). Each capability is a Rust crate compiled to `wasm32-unknown-unknown` against the [wasm-pdk](https://github.com/dylan-sutton-chavez/edge-python/tree/main/wasm-pdk) ABI. Hosts load the resulting `.wasm` over the standard plugin contract, no custom embedder, no Rust on the consumer side.
3
+
Official standard-library packages for [Edge Python](https://edgepython.com). Most are a Rust crate compiled to `wasm32-unknown-unknown` against the [wasm-pdk](https://github.com/dylan-sutton-chavez/edge-python/tree/main/wasm-pdk) ABI; hosts load the resulting `.wasm` over the standard plugin contract, no custom embedder, no Rust on the consumer side. A package can also ship as pure Edge Python source (`src/entry.py`), imported as a code module with no `cargo` build (e.g. `test`).
4
4
5
5
## Layout
6
6
7
7
```
8
8
tests/, agnostic Deno + Playwright runner driving the <edge-python> tag
9
-
<name>/, one folder per stdpkg crate, with src/, README.md, and <name>.json corpus
9
+
<name>/, one folder per stdpkg, with src/, README.md, and <name>.json corpus
10
10
```
11
11
12
-
The folder name IS the package name IS the wasm artifact name (e.g. `json/` -> `json/target/wasm32-unknown-unknown/release/json.wasm`). Each package's `<name>.json` sits alongside `Cargo.toml`; cases in it are automatically prefixed with `from <name> import *\n` before dispatch, so the corpus only contains the code being tested.
12
+
The folder name IS the package name. A native package builds to `<name>/target/wasm32-unknown-unknown/release/<name>.wasm`; a pure-Python package has `src/entry.py` and no build artifact. Each package's `<name>.json`corpus sits in its folder; cases in it are automatically prefixed with `from <name> import *\n` before dispatch, so the corpus only contains the code being tested.
13
13
14
14
## Packages
15
15
@@ -18,13 +18,14 @@ The folder name IS the package name IS the wasm artifact name (e.g. `json/` -> `
18
18
|`json`| JSON serialization/deserialization, see [`json/README.md`](json/README.md)|
19
19
|`re`| Regular expressions, a subset with capture, backreferences, lookaround, and a ReDoS step budget, see [`re/README.md`](re/README.md)|
20
20
|`math`| CPython-style math over libm, integer ops, and a packed-f64 batch fast path, see [`math/README.md`](math/README.md)|
21
+
|`test`| Tiny unit-test harness in pure Edge Python (fixtures, `raises`, runner with exit code), see [`test/README.md`](test/README.md)|
21
22
22
23
## Build + test
23
24
24
-
Each package builds independently; the agnostic runner asserts against the produced `.wasm`. From the repo root:
25
+
Native packages build independently; the agnostic runner asserts against the produced `.wasm`, or against `src/entry.py` for a pure-Python package. From the repo root:
25
26
26
27
```bash
27
-
# Build every package's .wasm artifact.
28
+
# Build a native package's .wasm artifact (skip for pure-Python packages like test).
28
29
( cd json && cargo build --release --target wasm32-unknown-unknown )
29
30
30
31
# One command, drives all corpora through the shared runner.
@@ -35,11 +36,15 @@ The runner discovers packages by walking the repo root for `<name>/<name>.json`
35
36
36
37
## Adding a new stdpkg
37
38
39
+
For a native (wasm) package:
40
+
38
41
1. Create `<name>/` at the repo root with `Cargo.toml` (`name = "<name>"`, `crate-type = ["cdylib"]`, `wasm-pdk` dep) and a `src/lib.rs` exporting via `#[plugin_fn]`.
39
42
2. Drop `<name>/<name>.json` with the corpus (Edge Python source + expected `output` / `error` per case).
40
43
3. Run `cargo build --release --target wasm32-unknown-unknown` inside the package folder.
41
44
4. Run `deno test --allow-all tests/` from the repo root.
42
45
46
+
For a pure-Python package, skip the crate: add `<name>/src/entry.py` plus `<name>/<name>.json`, then run `deno test --allow-all tests/`. The runner routes `.py` packages to their source and skips the wasm build.
0 commit comments