Replies: 2 comments 3 replies
-
Hi @phlpphns, thanks for the question, sorry for the delayed response. This sounds like a complicated project, and tbh I'm only just learning about wasm too (#2412), so it might take us a bit of iteration to find a solution for you. To start, can I ask a bit more about how you want to distribute and run this program? You wrote:
Does this mean that you'll compile everything to a set of wasm files and then launch it with |
Beta Was this translation helpful? Give feedback.
-
Based on your questions, I did further research and thinking. I present my thought and possibly point (b) below could be a way. I think that a browser based GUI might be most suitable for shipping and design. Concerning webassembly, something that has a python interpreter exists: pyiodide and pyscript. https://github.com/pyodide/pyodide/discussions They appear to support one python version only though (pyodide/pyodide#2353) and they are not fully functional (e.g. multiprocessing apparently cannot be invoked due to limits with the wasm) and also do I doubt that new modules can be loaded. I want to be able to load arbitrary modules on runtime. I want to be able to run code on runtime. I think defining the location of the python runtime by e.g., a configfile to be able to chose a python version and location and to install new modules might be beneficial. One could then decide if the codes that do the main work should be client or server sided, if it's not called from localhost (or so...). As far as I see it, pyO3 is "stuck" with the python version, the binary is created at. What to do? Some routes could exist: https://docs.python.org/3/library/code.html But I would not get a wasm solution from a python program because of difficulties owing to dynamic typing in python and wasm being statically typed. b1) I could try to build a webapp completely in python and see if I could integrate a REPL. Assuming we chose (b2) or (b3). I don't know yet if something like a REPL with autocomplete was already realized for a webfrontend. At least something like a text editor with a history should be realistic. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there,
Could you suggest a way how to integrate a python console into my Rust app (as part of a gui would be top)? I would like to distribute a set of python interfaced Rust libraries bundled with a gui (and python?). I am thinking about doing it with wasm (has some advantages).
The goal would be to give a working flow and structuring for users by the gui, the python interpreter should enable data processing, preparation, population with data objects and calculating quantities from the values in the data objects and add flexibility. How could one bind things together?
I posted two separate questions in the Rust language forum concerning the issue:
https://users.rust-lang.org/t/discussion-about-code-design-connecting-gluing-rust-libraries-by-python-and-minimizing-costs-for-type-conversion/75943
https://users.rust-lang.org/t/building-a-gui-in-rust-classical-vs-wasm-having-an-interface-console-for-scripting-to-e-g-python/75999
One suggestion concerning wasm was to (since it's html) pipe text both ways and drop it in a terminal library, e.g., https://www.npmjs.com/package/@piopli/terminal-ui
I am really unsure if this is the way to go for integrating a python interpreter into the program. - I think that an overall design would be a "list" of "Rust data objects" that provide and take the input and output for/of various functions. The list links the gui elements and is accessible from python and Rust (gui). The gui and python would have acces to the objects in the list (creating, deleting, extracting, plotting, saving to disk... objects and all kinds of stored data). Python should be able to load all libraries. I think once I have some minimal example I would be able to arrive at more and contribute to the ecosystem.
One idea that comes into my mind would be to use something like eval, run... as found in the documentation, but they are working internally only:
https://pyo3.rs/v0.9.2/python_from_rust.html
https://pyo3.rs/v0.9.2/get_started.html?highlight=interpreter#using-python-from-rust
https://pyo3.rs/master/python_from_rust.html
In my research I found some realizations, so the idea should be working but some don't even compile or cannot load modules, and I cannot figure out how to do it with pyo3 (or at all).. Others are not available in Rust or very slow.
I do not say that the gui must be written in Rust (would be nice though) or that it must be in wasm necessarily (a gui like egui would be acceptable too; all comments and hints would be very welcome!)
https://www.itp.uni-hannover.de/en/groups/weimer/teaching/ideal-gas-simulator/rapid-python-gui-development-with-html5-and-pyodide/
https://testdriven.io/blog/python-webassembly/
https://github.com/amirtds/python_editor_wasm.git
https://wapm.io/_/python
https://rustpython.github.io/demo/
https://github.com/RustPython/RustPython
thank you,
Phil
Beta Was this translation helpful? Give feedback.
All reactions