-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add a way to inject modules to rustpython_wasm #2402
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
Conversation
Thanks @coolreader18 for the quick fix. I created new crate and cargo.toml looks like -
And lib.rs looks like
I have added simple mymodule.py file in deps folder which has one simple function When I try to run
Any idea, if I am missing something? |
Oh whoops, yeah, add |
Sorry @coolreader18 for too many questions. This time cargo build succeeds, but when I ran
May be because |
Oh, hmmmm. I didn't think that the one in rustpython_wasm would count since it isn't really exported. |
@satyajeetkolhapure try adding |
I managed to run new package with new changes. I am not sure how to use it though. I created mymodule.py inside deps folder in my new crate. Created pkg using wasm-pack command. mymodule.py looks like below
Then I created main.py like below
I then created runwasm.js like below
But I am getting below error
Any idea? |
You should call |
@coolreader18 : You are awesome. It worked. Thank you so much for all your help and solving this problem. I will keep you posted when I try it with pytezos library. |
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 tested it. It works.
While testing it for pytezos, I am getting error because of other dependencies which pytezos needs. Is it possible to copy whole venv as well with this? When I copy the whole venv folder inside deps folder, somehow it does not find packages. e.g I have venv folder with all site-packages and one python file which uses those dependencies. How can I achieve it? Is there any way to add venv? |
@satyajeetkolhapure you should be able to point the |
@coolreader18 Somehow when I add packages folder with py_freeze, it is not able to detect it. I did below steps -
Is it possible to add it as standard library. I mean if I copy all pytezos libraries inside pylib-crate/Lib folder on my local machine vm repository, will those be added as standard libraries? or do I need something more than just copying? |
@satyajeetkolhapure that's really weird, you can definitely try copying everything in deps/ to |
@coolreader18 : Below are the folders and files inside deps folder pycache I will give it a try copying all these inside Lib folder of rustpython |
Hi @coolreader18 : I am using python3.7 to create those packages. Probably, this is causing it, may be because of obsolete import rather than relative. Which version of python interpreter RustPython uses? |
We don't really have a specific version we target, we're a mishmash of anywhere from 3.5 to 3.9. Have you changed your lib.rs at all? It's still |
yes. it is still the same I tried even copying all those files in Libs folder in vm. Somehow it found the main module. But it failed to find submodule. the paths used are obsolute. Not sure if that is the reason. |
Which paths? (assuming you mean absolute). Like the imports are |
There might be some unresolved issues with recursive relative imports, I know there are a few instances in the standard library we've had to work around. |
correct import pytezos.rpc is throwing error could you help me with the workaround? if possible. if you point me to any example of workaround |
Were you ever able to get it working in the first place? Trying to import pytezos just using the native rustpython binary seems to error in a bunch of different ways. |
When I create new python project and installed pytezos package, I called pytezos as below
Then I ran it in pycharm. I also tried command It gave me output
I had to install below two on mac os
pytezos documentation link - https://pypi.org/project/pytezos/ Appreciate your help @coolreader18 |
Right, but were you ever able to get it working in rustpython? RustPython isn't fully compatible with CPython yet, and looking at what |
I was not able to run it using rustpython yet. Possible. I think, I need to wait for those native modules be part of rustpython then. Will it be a long task to add those native modules? Just to get an idea |
Well it wouldn't really be adding them, it would be adding support for native extensions. Alternatively, you could translate every native module that pytezos depends on to rust and include it in your wasm binary, but I don't even know if that's possible - it looks like there's lots of crypto stuff as well as http requests, which can't be made from wasm |
Sorry for "leading you on" for so long, I hadn't ever looked up what pytezos is until today, I don't think it's possible to run in rustpython at the moment |
@coolreader18 no problem mate |
cc @satyajeetkolhapure
To add your own modules, you should make your own crate that depends on
Then your lib.rs should look like:
deps/
should be a directory next to your Cargo.toml, with a subdirectorydeps/pytezos
with stuff likedeps/pytezos/__init__.py
.