bytecodealliance / componentize-py

Apache License 2.0
147 stars 16 forks source link

Broken http example: import error from poll_loop.py: StreamErrorClosed #82

Closed jpwarren closed 5 months ago

jpwarren commented 5 months ago

Attempting an example for the first time, and it looks like there's a typo in the example code.

I run componentize-py -d ../../wit -w wasi:http/proxy@0.2.0 componentize app -o http.wasm and get this traceback:

Traceback (most recent call last):
  File "/home/daedalus/src/wasm-experiments/.venv/bin/componentize-py", line 8, in <module>
    sys.exit(script())
AssertionError: Traceback (most recent call last):
  File "/0/app.py", line 10, in <module>
    import poll_loop
  File "/bundled/poll_loop.py", line 17, in <module>
    from proxy.imports.streams import StreamErrorClosed, InputStream
ImportError: cannot import name 'StreamErrorClosed' from 'proxy.imports.streams' (/world/proxy/imports/streams.py). Did you mean: 'StreamError_Closed'?

It looks like bundled/poll_loop.py does indeed try to import and use StreamErrorClosed instead of StreamError_Closed, but when I try to make the change locally (so I can maybe file a PR), it doesn't appear to fix the error.

I clearly don't understand how Python imports work with wasmtime and/or componentize-py. What am I missing? Is it pulling in the import from another path or a prebuilt module somewhere?

No rush, just wanted to start learning about wasm and coming from my background with Python seemed a reasonable entry point.

dicej commented 5 months ago

Thanks so much for reporting this @jpwarren. This is a good reminder that (per #15), we need to be testing all the examples in CI. I've been doing spot checks of one or two examples periodically, but clearly I missed this one.

You were right about editing bundled/poll_loop.py, but the build.rs script that pulls it into the componentize-py binary wasn't smart enough to re-run when files under the bundled directory change, which I've just fixed. I've also fixed the example and tested all the other examples: https://github.com/bytecodealliance/componentize-py/pull/83