-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[RFC] A fake module from source API (mostly for wasm targets) #5041
Comments
@DimitrisJim @coolreader18 Do you have advices? |
Not relevant to naming, but I thought the standard procedure was to make the scope's locals be the actual dict of the module itself? |
Ok, I thought there was some sort of function like this already, found it: RustPython/wasm/lib/src/vm_class.rs Lines 274 to 309 in bdb0c8f
|
Not totally sure if that's the right naming, but it's prior art at least. Though inject_module does feel good I think, inject isn't overloaded with much in Python so that could be a good choice |
Oh though maybe your proposal wouldn't add it to sys.modules? That feels like the actual "injection" in the operation inject_module performs. |
Thank you! |
Yes. Context: we can have python sources with custom functions and call them with arguments, instead of running them. Currently we have to import the python source file. Some applications wouldn't want or even have permission to write to files. |
Summary
Provides an API
VirtualMachine::compile_module
that creates a Python module from source code.Detailed Explanation
We can use
vm.compile
andbuiltins.exec
to provide dynamic libraries without system IO.Below is not actual code, but it shows the general flow.
We can package these complex procedures into a single function.
The WASM architecture limits the use of Python modules due to access to system io.
Currently, the only way to use Python modules in WASM is to freeze them at compile time.
This API is not only limited to WASM, but will be very useful for WASM.
Drawbacks, Rationale, and Alternatives
import
in the name, likevm.import_from_source
, because in Python,import
implies complex filesystem usage viaimportlib
.Unresolved Questions
The text was updated successfully, but these errors were encountered: