-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix binding generation for lists; add cli test #46
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "componentize-py" | ||
version = "0.7.0" | ||
version = "0.7.1" | ||
edition = "2021" | ||
exclude = ["cpython"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Example: `cli` | ||
|
||
This is an example of how to use [componentize-py] and [Wasmtime] to build and | ||
run a Python-based component targetting the [wasi-cli] `command` world. | ||
|
||
Note that, as of this writing, `wasi-cli` has not yet stabilized. Here we use a | ||
snapshot, which may differ from later revisions. | ||
|
||
[componentize-py]: https://github.com/bytecodealliance/componentize-py | ||
[Wasmtime]: https://github.com/bytecodealliance/wasmtime | ||
[wasi-cli]: https://github.com/WebAssembly/wasi-cli | ||
|
||
## Prerequisites | ||
|
||
* `Wasmtime` 15.0.1 (later versions may use a different, incompatible `wasi-cli` snapshot) | ||
* `componentize-py` 0.7.1 | ||
|
||
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime` since, | ||
as of this writing, 15.0.1 has not yet been released. Once it has been | ||
released, you'll be able to download and install from | ||
https://github.com/bytecodealliance/wasmtime/releases/tag/v15.0.1. | ||
|
||
``` | ||
cargo install --locked --git https://github.com/bytecodealliance/wasmtime --branch release-15.0.0 wasmtime-cli | ||
pip install componentize-py | ||
``` | ||
|
||
## Running the demo | ||
|
||
``` | ||
componentize-py -d ../../wit -w wasi:cli/command@0.2.0-rc-2023-11-10 componentize app -o cli.wasm | ||
wasmtime run --wasm component-model cli.wasm | ||
``` | ||
|
||
The `wasmtime run` command above should print "Hello, world!". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from command import exports | ||
|
||
class Run(exports.Run): | ||
def run(self): | ||
print("Hello, world!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Example: `matrix-math` | ||
|
||
This is an example of how to use [componentize-py] to build a CLI app that does | ||
matrix multiplication using [NumPy] inside a sandboxed environment. This | ||
demonstrates using a non-trivial Python package containing native extensions | ||
within a guest component. | ||
|
||
[componentize-py]: https://github.com/bytecodealliance/componentize-py | ||
[NumPy]: https://numpy.org | ||
|
||
## Prerequisites | ||
|
||
* `wasmtime` 15.0.1 (later versions may use a different, incompatible `wasi-cli` snapshot) | ||
* `componentize-py` 0.7.1 | ||
* `NumPy`, built for WASI | ||
|
||
Note that we use an unofficial build of NumPy since the upstream project does | ||
not yet publish WASI builds. | ||
|
||
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime` since, | ||
as of this writing, 15.0.1 has not yet been released. Once it has been | ||
released, you'll be able to download and install from | ||
https://github.com/bytecodealliance/wasmtime/releases/tag/v15.0.1. | ||
|
||
``` | ||
cargo install --locked --git https://github.com/bytecodealliance/wasmtime --branch release-15.0.0 wasmtime-cli | ||
pip install componentize-py | ||
curl -OL https://github.com/dicej/wasi-wheels/releases/download/canary/numpy-wasi.tar.gz | ||
tar xf numpy-wasi.tar.gz | ||
``` | ||
|
||
## Running the demo | ||
|
||
``` | ||
componentize-py -d wit -w matrix-math componentize app -o matrix-math.wasm | ||
wasmtime run --wasm component-model matrix-math.wasm '[[1, 2], [4, 5], [6, 7]]' '[[1, 2, 3], [4, 5, 6]]' | ||
``` | ||
|
||
The second command above should print the following: | ||
|
||
``` | ||
matrix_multiply received arguments [[1, 2], [4, 5], [6, 7]] and [[1, 2, 3], [4, 5, 6]] | ||
[[9, 12, 15], [24, 33, 42], [34, 47, 60]] | ||
``` | ||
|
||
If you run into any problems, please file an issue! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This app can either be used as a library (by calling `matrix-math#multiply`) | ||
# or a CLI command (by calling `wasi:cli/run#run`) | ||
|
||
import sys | ||
import numpy | ||
import matrix_math | ||
from matrix_math import exports | ||
from matrix_math.types import Err | ||
|
||
class MatrixMath(matrix_math.MatrixMath): | ||
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() | ||
|
||
class Run(exports.Run): | ||
def run(self): | ||
args = sys.argv[1:] | ||
if len(args) != 2: | ||
print(f"usage: matrix-math <matrix> <matrix> (got {args})", file=sys.stderr) | ||
exit(-1) | ||
|
||
print(MatrixMath().multiply(eval(args[0]), eval(args[1]))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
world matrix-math { | ||
include wasi:cli/command@0.2.0-rc-2023-11-10; | ||
|
||
export multiply: func(a: list<list<float64>>, b: list<list<float64>>) -> result<list<list<float64>>, string>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dicej when I run this I get the following error:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's part of what this PR fixes. You'll either need to build
componentize-py
from the branch this PR intends to merge, or wait until it's merged and I've published v0.7.1 to PyPI.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge this and do a release once CI finishes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v0.7.1 is live: https://pypi.org/project/componentize-py/
If you install that, plus Wasmtime from the
release-15.0.0
branch (e.g.cargo install --locked --git https://github.com/bytecodealliance/wasmtime --branch release-15.0.0 wasmtime-cli
), you should be able to run either of the CLI examples.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @dicej, sorry for the delay in testing this out. I was able to test it out again and running the matrix-math example, I get the following error:
I'm pretty sure I updated all my deps to the latest. Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does
wasmtime --version
report? It needs to be 15.0.1 (or later), which includes bytecodealliance/wasmtime#7613, which addresses this issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doh you're right! I was still using v15.0.0. I did the
cargo install
for the new version, but forgot that I had originally installed viabash
, so cargo did install the new version but my path was using the bash installed version.After upgrading this all worked. Thanks for being so patient and for getting this working! =)