Skip to content
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

[do not merge] test python support #452

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

andreaTP
Copy link
Collaborator

Most of the projects to run Python on WASI are in a bad state, so, I think that we should not test in CI against outdated toolchains.

That said, this tutorial:
https://wasmlabs.dev/articles/python-wasm32-wasi/

kind of works for dummy examples.

@andreaTP andreaTP requested a review from electrum July 30, 2024 13:51
@electrum
Copy link
Collaborator

electrum commented Jul 30, 2024

Note that Python 3.13 has official support for WASI, so that seems reasonable to target, although you have to compile from source as it is not yet released (I don't know if they will have an official WASI binary).

var script = "print(\"hello python!\")";

FileWriter fileWriter = new FileWriter(new File("/tmp/try-python-wasm").toPath().resolve("test.py").toFile());
PrintWriter printWriter = new PrintWriter(fileWriter);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you can use Files.writeString()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

var fakeStdout = new MockPrintStream();
var fakeStderr = new MockPrintStream();
FileSystem fs =
Jimfs.newFileSystem(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add an <optional>true</optional> dependency on Jimfs and add a utility method for this?

@andreaTP
Copy link
Collaborator Author

@electrum I found some unofficial CPython Wasi pre-releases:
https://github.com/brettcannon/cpython-wasi-build

And it works!
When we import sys we trigger a ton of code to be loaded and the execution is extremely slow (40+ seconds on my machine).
I think that having a "longish running" real world code to run is useful to run tools(e.g. VisualVM) 🙂

@electrum
Copy link
Collaborator

electrum commented Jul 31, 2024

It's possible to use wizer to improve startup time after you've run all the imports statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants