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
[Proposal] pyodide-importer
package for external Python file import support
#1917
Comments
Another thing that would be really great for dev environments in Chromium to have an emscripten file system using File System Access API. Then you could just allow File System Access API to access dev directory, mount it into emscripten file system, add it to |
Indeed. Though File System Access API is currently available for only Chrome and Edge, there are products like vscode.dev that uses this API. It would be helpful to look around how they fully utilized File System Access API. |
BTW, vscode.dev team mentioned Pyodide on there blog post.
|
Thanks for the proposal @ryanking13 ! Sounds like an interesting project idea. Overall +1 to add this as a separate repo to the Pyodide org.
It would probably need some defaults. As far as I understand you don't want to put them in
Is it the presence of the
Interesting I wonder if would make sense to you a context manager for the API as they do. No strong opinions about it either way. Functions as you proposed also works. It's just gives a bit less flexibility is there are several remote URLs. |
I think I once thought of using root directory (which can be considered as a cwd) as a default, as users can easily
The problem is when
Yeah, providing a context manager API would be nice! |
This looks like some interesting stuff. There's probably some discussions over on #1715 (comment) that may be of interest, where @stefnotch has even has some links to demonstrations that would make working with multiple application (or even user) files more natural. Alas, haven't had enough time to work on jupyterlite to explore the FS API further....
However, in the tinkering i have been able to do, I've been wondering if putting the user's files-of-interest (and
We've started tinkering with some additional sources of wheels for |
Yes. Having a proper home directory would be more natural.
This would be interesting. I'll look into it. Thanks! |
@ryanking13 thank you for this proposal. It is great.
I wonder why we can not use async to achieve this and why using a compressed wheel is doable. When |
I thought like before this because the Python import system itself is synchronous, but we can truly investigate whether we can use async for this.
I thought of |
Update: Minimal implementation of |
Can it list available modules? |
For now, it's possible by: pyfinder = register_hook(...)
print(pyfinder.modules) |
Very nice! The readme could use a one or two sentence description mentioning what it does (and how it does it) at the beginning. Would you prefer to keep it under your account or move it to the pyodide org? (For the second option you can transfer it to me, so I can transfer it there.) |
Hello @ryanking13, I like the idea of your package and can only comply with @rth, please add more sentences about its use case. Can't we generally make this package a part of the Pyodide standard, like micropip? |
Yes, I will add more documentation and functionalities, and I will add this to the related projects section when it becomes more stable.
I want to move this to pyodide org when it becomes more stable. For now, it's kind of PoC and needs more tests and functionalities. |
I didn't know this. Thanks, @phorward, It will be really helpful!
Well, I'm not sure which is the best way to support external file import. We have been discussing this in #1876 (and also in other issues). Another way that @hoodmane suggested is |
OK so what should be done with this issue @ryanking13, do you want to move https://github.com/ryanking13/pyodide-importer to the Pyodide org (if you are still interested in maintaining it) ? |
I don't actively develop |
Problem statement
Currently, Pyodide doesn't support importing external Python packages (.py) except for installing a pure Python package wheel (.whl) or Pyodide Python packages(.js, .data) through
micropip.install
orpyodide.loadPackage
.This is because the external Python files need to be accessed through HTTP(s) (browser) or File System API (node) while the import statements try to find them inside the virtual file system.
So for now, if someone wants to use external python files, they need to fetch and execute them manually, which is not very straightforward.
Proposal
This issue proposes the
pyodide-importer
which is a Python package that supports seamless import statement support for Pyodide applications.Idea
When
import
statement is called, Python tries to find the import candidates throughPathFinder
registered insys.meta_path
.pyodide-importer
defines a new Python PathFinder (e.g. PyodidePathFinder), which is appended to thesys.meta_path
, that searches and downloads import candidates through HTTP(s) and File System API.API design (draft)
Limitations
.pyc
,.pyd
,.so
, or.zip
is unavailable.For example,
import parent.module
is not supported if the file is located such as:Solutions from other projects
Update
Minimal implementation of pyodide-importer is here:
https://github.com/ryanking13/pyodide-importer
The text was updated successfully, but these errors were encountered: