- Notifications
You must be signed in to change notification settings - Fork1.4k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
satyajeetkolhapure commentedJan 20, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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? |
coolreader18 commentedJan 20, 2021
Oh whoops, yeah, add |
satyajeetkolhapure commentedJan 20, 2021
Sorry@coolreader18 for too many questions. This time cargo build succeeds, but when I ran May be because |
coolreader18 commentedJan 20, 2021
Oh, hmmmm. I didn't think that the one in rustpython_wasm would count since it isn't really exported. |
coolreader18 commentedJan 20, 2021
@satyajeetkolhapure try adding |
satyajeetkolhapure commentedJan 21, 2021
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? |
coolreader18 commentedJan 21, 2021
You should call |
satyajeetkolhapure commentedJan 22, 2021
@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. |
satyajeetkolhapure left a comment
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.
satyajeetkolhapure commentedJan 23, 2021
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? |
coolreader18 commentedJan 23, 2021
@satyajeetkolhapure you should be able to point the |
satyajeetkolhapure commentedJan 25, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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? |
coolreader18 commentedJan 26, 2021
@satyajeetkolhapure that's really weird, you can definitely try copying everything in deps/ to |
satyajeetkolhapure commentedJan 26, 2021
@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 |
satyajeetkolhapure commentedJan 26, 2021
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? |
coolreader18 commentedJan 26, 2021
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 |
satyajeetkolhapure commentedJan 26, 2021
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. |
coolreader18 commentedJan 26, 2021
Which paths? (assuming you mean absolute). Like the imports are |
coolreader18 commentedJan 26, 2021
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. |
satyajeetkolhapure commentedJan 26, 2021
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 |
coolreader18 commentedJan 26, 2021
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. |
satyajeetkolhapure commentedJan 26, 2021
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 |
coolreader18 commentedJan 26, 2021
Right, but were you ever able to get it working in rustpython? RustPython isn't fully compatible with CPython yet, and looking at what |
satyajeetkolhapure commentedJan 26, 2021
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 |
coolreader18 commentedJan 26, 2021
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 |
coolreader18 commentedJan 26, 2021
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 |
satyajeetkolhapure commentedJan 27, 2021
@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/pytezoswith stuff likedeps/pytezos/__init__.py.