Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.16.0"
version = "0.17.0"
edition = "2021"
exclude = ["cpython"]

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Then, use the `hello` module produced by the command above to write your app:

```shell
cat >app.py <<EOF
import hello
class Hello(hello.Hello):
import wit_world
class WitWorld(wit_world.WitWorld):
def hello(self) -> str:
return "Hello, World!"
EOF
Expand Down
10 changes: 5 additions & 5 deletions bundled/poll_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
import socket
import subprocess

from proxy.types import Ok, Err
from proxy.imports import types, streams, poll, outgoing_handler
from proxy.imports.types import (
from wit_world.types import Ok, Err
from wit_world.imports import types, streams, poll, outgoing_handler
from wit_world.imports.types import (
IncomingBody,
OutgoingBody,
OutgoingRequest,
IncomingResponse,
)
from proxy.imports.streams import StreamError_Closed, InputStream
from proxy.imports.poll import Pollable
from wit_world.imports.streams import StreamError_Closed, InputStream
from wit_world.imports.poll import Pollable
from typing import Optional, cast

# Maximum number of bytes to read at a time
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` 26.0.0 or later
* `componentize-py` 0.16.0
* `componentize-py` 0.17.0

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/v26.0.0.

```
cargo install --version 26.0.0 wasmtime-cli
pip install componentize-py==0.16.0
pip install componentize-py==0.17.0
```

## Running the demo
Expand Down
7 changes: 5 additions & 2 deletions examples/cli/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from command import exports

from wit_world import exports
from wit_world.imports.environment import get_arguments
import pdb

class Run(exports.Run):
def run(self) -> None:
if "--pdb" in get_arguments():
pdb.set_trace()
print("Hello, world!")
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` 26.0.0 or later
* `componentize-py` 0.16.0
* `componentize-py` 0.17.0

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/v26.0.0.

```
cargo install --version 26.0.0 wasmtime-cli
pip install componentize-py==0.16.0
pip install componentize-py==0.17.0
```

## Running the demo
Expand Down
8 changes: 4 additions & 4 deletions examples/http/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import hashlib
import poll_loop

from proxy import exports
from proxy.types import Ok
from proxy.imports import types
from proxy.imports.types import (
from wit_world import exports
from wit_world.types import Ok
from wit_world.imports import types
from wit_world.imports.types import (
Method_Get,
Method_Post,
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` 26.0.0 or later
* `componentize-py` 0.16.0
* `componentize-py` 0.17.0
* `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/v26.0.0.

```
cargo install --version 26.0.0 wasmtime-cli
pip install componentize-py==0.16.0
pip install componentize-py==0.17.0
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
10 changes: 5 additions & 5 deletions examples/matrix-math/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import sys
import numpy
import matrix_math
from matrix_math import exports
from matrix_math.types import Err
import wit_world
from wit_world import exports
from wit_world.types import Err


class MatrixMath(matrix_math.MatrixMath):
class WitWorld(wit_world.WitWorld):
def multiply(self, a: list[list[float]], b: list[list[float]]) -> list[list[float]]:
print(f"matrix_multiply received arguments {a} and {b}")
return numpy.matmul(a, b).tolist() # type: ignore
Expand All @@ -21,4 +21,4 @@ def run(self) -> None:
print("usage: matrix-math <matrix> <matrix>", file=sys.stderr)
exit(-1)

print(MatrixMath().multiply(eval(args[0]), eval(args[1])))
print(WitWorld().multiply(eval(args[0]), eval(args[1])))
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` 25.0.0 or later
* `componentize-py` 0.16.0
* `componentize-py` 0.17.0

```
pip install componentize-py==0.16.0 wasmtime==25.0.0
pip install componentize-py==0.17.0 wasmtime==25.0.0
```

## Running the demo
Expand Down
6 changes: 3 additions & 3 deletions examples/sandbox/guest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sandbox
from sandbox.types import Err
import wit_world
from wit_world.types import Err
import json


Expand All @@ -11,7 +11,7 @@ def handle(e: Exception) -> Err[str]:
return Err(f"{type(e).__name__}: {message}")


class Sandbox(sandbox.Sandbox):
class WitWorld(wit_world.WitWorld):
def eval(self, expression: str) -> str:
try:
return json.dumps(eval(expression))
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` 26.0.0 or later
* `componentize-py` 0.16.0
* `componentize-py` 0.17.0

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/v26.0.0.

```
cargo install --version 26.0.0 wasmtime-cli
pip install componentize-py==0.16.0
pip install componentize-py==0.17.0
```

## Running the demo
Expand Down
2 changes: 1 addition & 1 deletion examples/tcp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import asyncio
import ipaddress
from ipaddress import IPv4Address, IPv6Address
from command import exports
from wit_world import exports
from typing import Tuple


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.16.0"
version = "0.17.0"
description = "Tool to package Python applications as WebAssembly components"
readme = "README.md"
license = { file = "LICENSE" }
Expand Down
6 changes: 2 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,7 @@ pub extern "C" fn componentize_py_get_field<'a>(
.nth(field)
.unwrap_or(0);

unsafe { mem::transmute::<u32, i32>(value) }
.to_object(*py)
.into_bound(*py)
u32::cast_signed(value).to_object(*py).into_bound(*py)
}
Type::Option => match i32::try_from(field).unwrap() {
DISCRIMINANT_FIELD_INDEX => if value.is_none() { 0 } else { 1 }
Expand Down Expand Up @@ -865,7 +863,7 @@ pub unsafe extern "C" fn componentize_py_init<'a>(
slice::from_raw_parts(data, len)
.iter()
.map(|v| {
mem::transmute::<i32, u32>(
i32::cast_unsigned(
Bound::from_borrowed_ptr(*py, v.as_ptr()).extract().unwrap(),
)
})
Expand Down
23 changes: 12 additions & 11 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ pub struct Common {
/// name.
#[arg(long, value_parser = parse_key_value)]
pub export_interface_name: Vec<(String, String)>,

/// Optional name of top-level module to use for bindings.
///
/// If this is not specified, the module name will default to "wit_world".
#[arg(long)]
pub world_module: Option<String>,
}

#[derive(clap::Subcommand, Debug)]
Expand Down Expand Up @@ -126,12 +132,6 @@ pub struct Bindings {
///
/// This will be created if it does not already exist.
pub output_dir: PathBuf,

/// Optional name of top-level module to use for bindings.
///
/// If this is not specified, the module name will be derived from the world name.
#[arg(long)]
pub world_module: Option<String>,
}

fn parse_key_value(s: &str) -> Result<(String, String), String> {
Expand All @@ -157,7 +157,7 @@ fn generate_bindings(common: Common, bindings: Bindings) -> Result<()> {
common.world.as_deref(),
&common.features,
common.all_features,
bindings.world_module.as_deref(),
common.world_module.as_deref(),
&bindings.output_dir,
&common
.import_interface_name
Expand Down Expand Up @@ -189,6 +189,7 @@ fn componentize(common: Common, componentize: Componentize) -> Result<()> {
common.world.as_deref(),
&common.features,
common.all_features,
common.world_module.as_deref(),
&python_path.iter().map(|s| s.as_str()).collect::<Vec<_>>(),
&componentize
.module_worlds
Expand Down Expand Up @@ -339,6 +340,7 @@ mod tests {
let common = Common {
wit_path: Some(wit.path().into()),
world: None,
world_module: Some("bindings".into()),
quiet: false,
features: vec![],
all_features: false,
Expand All @@ -347,7 +349,6 @@ mod tests {
};
let bindings = Bindings {
output_dir: out_dir.path().into(),
world_module: None,
};
generate_bindings(common, bindings)?;

Expand All @@ -369,6 +370,7 @@ mod tests {
let common = Common {
wit_path: Some(wit.path().into()),
world: None,
world_module: Some("bindings".into()),
quiet: false,
features: vec!["x".to_owned()],
all_features: false,
Expand All @@ -377,7 +379,6 @@ mod tests {
};
let bindings = Bindings {
output_dir: out_dir.path().into(),
world_module: None,
};
generate_bindings(common, bindings)?;

Expand All @@ -399,6 +400,7 @@ mod tests {
let common = Common {
wit_path: Some(wit.path().into()),
world: None,
world_module: Some("bindings".into()),
quiet: false,
features: vec![],
all_features: true,
Expand All @@ -407,7 +409,6 @@ mod tests {
};
let bindings = Bindings {
output_dir: out_dir.path().into(),
world_module: None,
};
generate_bindings(common, bindings)?;

Expand All @@ -427,6 +428,7 @@ mod tests {
let common = Common {
wit_path: Some(wit.path().into()),
world: None,
world_module: Some("bindings".into()),
quiet: false,
features: vec!["x".to_owned()],
all_features: false,
Expand All @@ -435,7 +437,6 @@ mod tests {
};
let bindings = Bindings {
output_dir: out_dir.path().into(),
world_module: None,
};
generate_bindings(common.clone(), bindings)?;
fs::write(
Expand Down
Loading
Loading