-
Notifications
You must be signed in to change notification settings - Fork 40
Add bootstrapCode config option #172
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
Conversation
ping @jtpio |
Thanks @juntyr. Having it implemented via such option sounds like a fine approach. Also when there is something to help better see the logs (jupyterlite/jupyterlite#1498), it will be easier for users to troubleshoot issues if something goes wrong with this extra |
Again, this is a feature that also does not exist in JupyterLab, and for which there are user space extensions. For "pre-installing" packages, there are also other approaches such as jupyterlite-pyodide-lock, which put everything known packages into |
Could you please point towards one? If there’s an existing extension that can do that I’d be very happy to use it and close this PR.
That just preloads them, but doesn’t run them. What this PR tries to provide is a way to run custom code during bootstrap, which is not yet possible otherwise (as far as I know). At the moment, I have to use some very hacky patches to IPython to get some code to run after the interpreter is setup but before the user gains control. This is very valuable for applying behind-the-scenes magic that the user doesn’t need to see. |
Here is a discourse discussion with more context (and related links at the bottom): https://discourse.jupyter.org/t/setting-initialization-cells-for-jupyterlab/13345 |
Are any of these solutions not tied to notebooks? I’m looking for something that can be configured by the host of JupyterLite, not something that needs to be configured by the notebook author |
@juntyr would you still like to document your approach, for example in https://jupyterlite.readthedocs.io/en/stable/howto/index.html#configuring-the-pyodide-kernel? So it can be useful to other people too. |
Right now the approach requires controlling the Pyodide build, as I need to make emscripten embed the IPython config files into the filesystem. The rest is already documented by https://modelpredict.com/how-to-write-reliable-scripts-ipython/, I just copied its code. So in the end we have:
def load_ipython_extension(ip):
# do stuff here |
The new
bootstrapCode
extension config option allows JupyterLite hosts to run custom Python code before the kernel starts. This should help downstream projects with the commonly wanted feature of "running code before the first cell".Related to #88