-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[IDEA] Web imports for WASM #659
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
Comments
Related to #228 |
I think that the solution at pyodide is a little more complex then what I suggest. I believe we should start from something simple like importing pure python code first. |
We could also use the PyPI API to fetch packages: https://warehouse.readthedocs.io/api-reference/json/; i.e. |
I think that we should start with synchronous fetch maybe by using |
What if we just had a WasmVM method/browser module export that accepted a module URL and returned a promise for when it was loaded? That way you would either load it from JS or do def main():
import module
browser.load_module("module", "https://module.url").then(main) |
This will work great with new code someone writes specifically for RustPython WASM. I think that we would like a solution that will allow a user to use existing code in the regular way he used to. rp.pyEval("import module; module.cool_func()", {"imports": {"module": "https://module.url"}}) |
I'm opposed to using synchronous fetch; it's effectively deprecated by web standards and having it be the main or only way to load Python modules would make for a horrible UX on sites that might use RustPython, as it freezes the entire page while it's loading. |
I totally agree with your point except that I would not like to force a user to convert every code he has for it to work. I don't have a good option but maybe we should let the user decide how to do it. Once the option to override |
Alright, I guess that's fair. |
Now that #914 is in I think the next steps are:
I think we might want to add some mechanism for "pre" imports that will allow defining a list of imports that will happen before the code is executed. |
Something I was thinking about was transforming the AST of a module that uses imports to be more like the example you gave for using |
When using our WASM code currently doing import to anything that is not packaged in the build (builtins, stdlib) will not work. I suggest we will allow import in a way very similar to any other web resource.
For example when we will run the following from
http://test.org/py.html
The WASM import will do a HTTP GET request to
http://test.org/test.py
and import the content of the file.We can also allow the users to add other paths to
sys.path
so the browser will try to look for the imported file there as well. I think that the paths should be treated like html paths:path/to/import
: will be relative to the current file./path/to/import
: will be absolute to the server root.imports
path at domainrustpypi.org
.We should probably add the js VirtualMachine a
setSysPath
function likesetStdout
.The text was updated successfully, but these errors were encountered: