Comments (4)
Thanks for reporting this, @k-mack. I'm having trouble reproducing it, though. Here's what I did:
docker run --rm -it --entrypoint bash python:3.10.14-slim
pip install componentize-py
apt-get update
apt-get install -y git curl
git clone https://github.com/bytecodealliance/componentize-py
cd componentize-py/examples/matrix-math/
curl -OL https://github.com/dicej/wasi-wheels/releases/download/v0.0.1/numpy-wasi.tar.gz
tar xf numpy-wasi.tar.gz
componentize-py -d ../../wit -w matrix-math componentize app -o matrix-math.wasm
That worked for me. Would you mind sharing the exact commands you're using?
from componentize-py.
Interesting. Your sequence of commands worked for me. There are a couple of differences in what I'm doing, but I'm not sure what's erroneous about it.
Here's the Dockerfile I use to create the image:
# Dockerfile.wasm-component
FROM python:3.10.14-slim
WORKDIR /workspace
# Deps
RUN apt-get update && apt-get install -y curl xz-utils zip && \
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v19.0.2/wasmtime-v19.0.2-x86_64-linux.tar.xz && \
tar --xz -xf wasmtime-v19.0.2-x86_64-linux.tar.xz && mv wasmtime-v19.0.2-x86_64-linux wasmtime && \
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
# Componentize-py src
RUN curl -LO https://github.com/bytecodealliance/componentize-py/archive/fa666b9c16e3f46ae4f77372add5f59443fe65eb.zip && \
unzip -d src fa666b9c16e3f46ae4f77372add5f59443fe65eb.zip && \
mv src/componentize-py-fa666b9c16e3f46ae4f77372add5f59443fe65eb src/componentize-py-fa666b9 && \
cp src/componentize-py-fa666b9/examples/matrix-math/app.py .
Build the image, run the container, and run componentize-py:
docker build -t componentize-py:test -f Dockerfile.wasm-component .
docker run --rm -it componentize-py:test /bin/bash
componentize-py --wit-path src/componentize-py-fa666b9/wit --world matrix-math componentize app -o matrix-math.wasm
The matrix-math world is in the wit path:
cat src/componentize-py-fa666b9/wit/matrix-math.wit
world matrix-math {
include wasi:cli/[email protected];
export multiply: func(a: list<list<float64>>, b: list<list<float64>>) -> result<list<list<float64>>, string>;
}
from componentize-py.
Okay, I figured it out. The problem is due to a combination of factors:
componentize-py
uses the current working directory as the Python path (i.e. the directory under which to search for the application code and any of its dependencies)- When generating a component, it searches the Python path (and all its subdirectories) for componentize-py.toml files, and if it finds any it uses them to locate WIT files
- The
componentize-py
source code contains a couple of componentize-py.toml files for testing, so when you unzip the source tree into a subdirectory of the current directory, it finds those files and tries to use them
You can avoid the above by removing the directory containing the test componentize-py.toml files, e.g. rm -r src/componentize-py-fa666b9/src/test
prior to running the componentize
subcommand.
There's currently a lot of implicit behavior in the componentize-py
CLI, leading to subtle issues like this. The motivation is to make it "do what you mean" most of the time, but sometimes it backfires. I'm open to suggestions about how to improve it and make it less surprising, while still making it do the right thing with minimal input.
from componentize-py.
Thanks, @dicej! I'll have to play around with componentize-py.toml files to get a better feel for the tool, and I'll contribute back any suggestions I may have along the way. I was able to componentize some Python code, transpile it with jco, and run it in the browser, which feels pretty good. Thanks again for your quick help.
from componentize-py.
Related Issues (20)
- Run MyPy on all test code and bindings HOT 1
- Running example HOT 3
- Question: Current types limitation HOT 6
- Matrix-math example - ImportError... HOT 4
- List errors which might be raised in function docstrings
- Make the types generated for WIT resources context managers
- feature: add zlib to cpython build HOT 1
- Generated component has dependency on wasi:cli/[email protected] HOT 14
- Create more actionable error for disallowed name for a Python module
- Broken http example: import error from poll_loop.py: StreamErrorClosed HOT 1
- Unresolved symbols when building from source HOT 2
- Type checking fails when records are defined in a world with functions HOT 1
- Issue encountered when trying to execute app.wasm using wasmtime HOT 3
- Allow dynamic imports in sandbox example HOT 6
- ImportError with NumPy when running matrix_math example HOT 8
- Http example doesn't work with Wasmtime 21.0.1 HOT 3
- [bug] zlib support required by widely used python modules HOT 4
- Use Python `bool` type instead of `int` for WIT `bool`s
- Feature request: Smaller wasm modules / binaries. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from componentize-py.