-
Notifications
You must be signed in to change notification settings - Fork 1
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
Lazy-install altair and tenacity #9
base: stlite-1.32.2
Are you sure you want to change the base?
Conversation
Loading time comparisonRun the following in local.
Resulthttps://docs.google.com/spreadsheets/d/1igepmz2APbnApCHzgQUOTiuUZzlsKmWZ8QR_b5qUNP8/edit#gid=0 Baseline (
|
TODO:
|
Is the code execution continued after the lazy install or does it require a rerun?
Is there a way to somehow communicate to the kernel about this installation and trigger a progress toast? Maybe we could use Another alternative might be to actually just create a toast via |
In general, I think it might not be worth adding this just for In the context of a playground, our ideal requirements would be to 1) have only a single file people are modifying (-> no requirements file) 2) have a very fast initial loading time (-> only have the min. number of dependencies pre-installed). With these requirements, probably the best option to allow users to use a variety of packages in the playground without impacting the overall performance is probably by having a smart auto-install feature. That means, as soon as there is an unknown import, stlite would try to auto-install this package. |
Btw. after some chatting with ChatGPT and Gemini there might be an alternative solution for the auto-install. E.g. maybe something like: import sys
import subprocess
import importlib.util
def install_and_import(package):
# Install & import the package
return True
class AutoInstallFinder:
def __init__(self):
self.installed = set()
def find_spec(self, fullname, path, target=None):
if fullname in self.installed:
return importlib.util.find_spec(fullname)
spec = importlib.util.find_spec(fullname)
if spec is not None:
return spec # Module found, no need to install
if fullname not in self.installed and install_and_import(fullname):
self.installed.add(fullname)
return importlib.util.find_spec(fullname)
return None # Module not found and installation failed or not attempted
sys.meta_path.insert(0, AutoInstallFinder()) But not sure how well that works in pyiodide. I did not have the time yet to explore in more depth. |
Yes, it requires rerun.
Yes, technically possible. It might be something like this:
I thought it's not worth doing as it would introduce too much complexity for limited supported packages, just same as your opinion, but now think it's not going to be so complex maybe?
Also totally agree with your playground example.
Yea, I also thought about it using a custom finder and loader, but it shouldn't work in stlite/Pyodide because the package installer ( FYI, such custom finder/importer approach is already used to support lazy-"import" (or lazy-patching) of |
For the playground example you provided, I think there is another approach: The differences in this case are
|
I came to think it's nice to implement such auto-package-installation as a part of stlite's API. |
I came up with this lazy-install idea.
However, with this naive implementation, looks like the drawback is larger then the benefit such as