Skip to content

Commit

Permalink
fix HTTP example (#83)
Browse files Browse the repository at this point in the history
Also, re-bundle `bundled` directory if any of its files change.

Fixes #82

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
  • Loading branch information
dicej committed Apr 10, 2024
1 parent 65277a5 commit 58c9430
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "componentize-py"
version = "0.13.2"
version = "0.13.3"
edition = "2021"
exclude = ["cpython"]

Expand Down
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ fn include(path: &Path) -> bool {
}

fn add(builder: &mut Builder<impl Write>, root: &Path, path: &Path) -> Result<()> {
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());

if path.is_dir() {
for entry in fs::read_dir(path)? {
add(builder, root, &entry?.path())?;
Expand Down
4 changes: 2 additions & 2 deletions bundled/poll_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from proxy.types import Ok, Err
from proxy.imports import types, streams, poll, outgoing_handler
from proxy.imports.types import IncomingBody, OutgoingBody, OutgoingRequest, IncomingResponse
from proxy.imports.streams import StreamErrorClosed, InputStream
from proxy.imports.streams import StreamError_Closed, InputStream
from proxy.imports.poll import Pollable
from typing import Optional, cast

Expand Down Expand Up @@ -61,7 +61,7 @@ async def next(self) -> Optional[bytes]:
else:
return buffer
except Err as e:
if isinstance(e.value, StreamErrorClosed):
if isinstance(e.value, StreamError_Closed):
if self.stream is not None:
self.stream.__exit__()
self.stream = None
Expand Down
4 changes: 2 additions & 2 deletions examples/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ run a Python-based component targetting the [wasi-cli] `command` world.
## Prerequisites

* `Wasmtime` 18.0.0 or later
* `componentize-py` 0.13.2
* `componentize-py` 0.13.3

Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
you don't have `cargo`, you can download and install from
https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.0.

```
cargo install --version 18.0.0 wasmtime-cli
pip install componentize-py==0.13.2
pip install componentize-py==0.13.3
```

## Running the demo
Expand Down
4 changes: 2 additions & 2 deletions examples/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ run a Python-based component targetting the [wasi-http] `proxy` world.
## Prerequisites

* `Wasmtime` 18.0.0 or later
* `componentize-py` 0.13.2
* `componentize-py` 0.13.3

Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
you don't have `cargo`, you can download and install from
https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.0.

```
cargo install --version 18.0.0 wasmtime-cli
pip install componentize-py==0.13.2
pip install componentize-py==0.13.3
```

## Running the demo
Expand Down
12 changes: 6 additions & 6 deletions examples/http/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from proxy.types import Ok
from proxy.imports import types
from proxy.imports.types import (
MethodGet, MethodPost, Scheme, SchemeHttp, SchemeHttps, SchemeOther, IncomingRequest, ResponseOutparam,
Method_Get, Method_Post, Scheme, Scheme_Http, Scheme_Https, Scheme_Other, IncomingRequest, ResponseOutparam,
OutgoingResponse, Fields, OutgoingBody, OutgoingRequest
)
from poll_loop import Stream, Sink, PollLoop
Expand All @@ -40,7 +40,7 @@ async def handle_async(request: IncomingRequest, response_out: ResponseOutparam)
path = request.path_with_query()
headers = request.headers().entries()

if isinstance(method, MethodGet) and path == "/hash-all":
if isinstance(method, Method_Get) and path == "/hash-all":
# Collect one or more "url" headers, download their contents
# concurrently, compute their SHA-256 hashes incrementally (i.e. without
# buffering the response bodies), and stream the results back to the
Expand All @@ -61,7 +61,7 @@ async def handle_async(request: IncomingRequest, response_out: ResponseOutparam)

sink.close()

elif isinstance(method, MethodPost) and path == "/echo":
elif isinstance(method, Method_Post) and path == "/echo":
# Echo the request body back to the client without buffering.

response = OutgoingResponse(Fields.from_list(list(filter(lambda pair: pair[0] == "content-type", headers))))
Expand Down Expand Up @@ -99,11 +99,11 @@ async def sha256(url: str) -> Tuple[str, str]:

match url_parsed.scheme:
case "http":
scheme: Scheme = SchemeHttp()
scheme: Scheme = Scheme_Http()
case "https":
scheme = SchemeHttps()
scheme = Scheme_Https()
case _:
scheme = SchemeOther(url_parsed.scheme)
scheme = Scheme_Other(url_parsed.scheme)

request = OutgoingRequest(Fields.from_list([]))
request.set_scheme(scheme)
Expand Down
4 changes: 2 additions & 2 deletions examples/matrix-math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ within a guest component.
## Prerequisites

* `wasmtime` 18.0.0 or later
* `componentize-py` 0.13.2
* `componentize-py` 0.13.3
* `NumPy`, built for WASI

Note that we use an unofficial build of NumPy since the upstream project does
Expand All @@ -23,7 +23,7 @@ https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.0.

```
cargo install --version 18.0.0 wasmtime-cli
pip install componentize-py==0.13.2
pip install componentize-py==0.13.3
curl -OL https://github.com/dicej/wasi-wheels/releases/download/v0.0.1/numpy-wasi.tar.gz
tar xf numpy-wasi.tar.gz
```
Expand Down
4 changes: 2 additions & 2 deletions examples/sandbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ sandboxed Python code snippets from within a Python app.
## Prerequisites

* `wasmtime-py` 18.0.0 or later
* `componentize-py` 0.13.2
* `componentize-py` 0.13.3

```
pip install componentize-py==0.13.2 wasmtime==18.0.2
pip install componentize-py==0.13.3 wasmtime==18.0.2
```

## Running the demo
Expand Down
4 changes: 2 additions & 2 deletions examples/tcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ making an outbound TCP request using `wasi-sockets`.
## Prerequisites

* `Wasmtime` 18.0.0 or later
* `componentize-py` 0.13.2
* `componentize-py` 0.13.3

Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
you don't have `cargo`, you can download and install from
https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.0.

```
cargo install --version 18.0.0 wasmtime-cli
pip install componentize-py==0.13.2
pip install componentize-py==0.13.3
```

## Running the demo
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ features = ["pyo3/extension-module"]

[project]
name = "componentize-py"
version = "0.13.2"
version = "0.13.3"
description = "Tool to package Python applications as WebAssembly components"
readme = "README.md"
license = { file = "LICENSE" }
Expand Down

0 comments on commit 58c9430

Please sign in to comment.