-
Notifications
You must be signed in to change notification settings - Fork 25
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
How can I handle imports? #40
Comments
You may want to have a look at Flexx. Flexx is able to detect functions/classes being used that are imported from other modules, and resolve everything. As long as your code does not use any unsupported builtins, anything related to the file system, and only pure Python, it should be able to compile everything. |
It's also possible to use just PScript. In that case you just compile each module, and handle imports e.g by writing |
Hi! First, I have to tell you I loved your talk "Let’s embrace WebAssembly!" How would I use Flexx to do that? I suppose imports in functions and dynamic imports are not supported. I am willing to improve PScript to support imports, is it within the scope of this project? |
Thanks :) well, Flexx and WebAssembly are mostly unrelated things. In the talk we've focused more on running WASM in Python, instead of the other way around. For running Python in the browser with WASM, which I assume is what you want to do, can be done in (at least) three ways:
In the first two your code is still Python - only the VM (i.e. the interpreter capable of running Python code) is compiled to wasm. The latter is probably the most interesting, since you'd also gain a speed benefit. But such a compiler does not yet exist :) It would be a bit like PScript, but with types (and therefore more predictable, no hidden weird JS behavior).
I'm not sure if it is within scope. But you could start by extracting the logic from Flexx and rolling that into a new project. The code is in flexx/app I should warn you though that this Flexx subpackage is where many things come together, so it's not the easiest code to navigate :) though most logic of your interest should be in |
Oh, sorry for the confusion! "that" = "detect functions/classes being used that are imported from other modules, and resolve everything" I know quite well about Pyodide (I use it here). I guess your third thing could be achieved with Cython + emscripten :) So my original question is: how would you transpile a module using flexx? |
Aha :)
The exact way to go depends on your goals, but at some point you'll have a main Flexx widget: class MyMainWidget(flx.Widget): # or maybe flx.PyWidget
def init(self):
super().init()
# ... this runs in JS.
# You can call existing Python functions here, and Flexx will pick it up,
# resolve everything that *that* code is using, etc. and then compile everything.
# Then you turn that into an app object
your_app = flx.App(MyMainWidget) The app object you can then For a more classical approach (and frankly, an approach that is a bit less magical) you can use The most important question is probably whether you want to convert your app to JS in full, or whether you need a server-client thing going on. |
Hi, I have a project with several files and modules. Is there a way to convert it simply to pscript?
The text was updated successfully, but these errors were encountered: