See USAGE.md for instructions on how to use this widget in Grist. This README is for developers.
This repo is a custom deployment of JupyterLite generated from https://github.com/jupyterlite/demo.
- Create and activate a virtual environment
pip install -r requirements.txt- In the
extensionfolder, runjlpm install, thenjlpm build, thenjlpm watch.jlpmis a pinned version ofyarnthat is installed with JupyterLab, so you can useyarnornpminstead.jlpm watchwill rebuild the extension when changes are made to the code underextension/src. For some reason it doesn't work without runningjlpm buildfirst at least once. - In a new tab, back in the repo root, activate the virtual environment again, then run
./dev.sh. This will start a local server at http://localhost:8000 which you can use as a custom widget URL. - Make some changes to the code under
gristorextension/src. Changing.tsfiles will rebuild the JS, but either way you still have to interrupt the server with Ctrl+C, rerun./dev.sh, and refresh the page to see the changes. - If you're having trouble, try various permutations of these commands:
pip uninstall grist_jupyterlab_widget(that's the Python package name of theextensionfolder)pip install -e extensionjupyter labextension develop ./extension(part ofdev.sh), maybe with the--overwriteflag.jlpm buildandjlpm watchwithin theextensionfolder
In the grist-widget repo, the jupyterlite folder is a git submodule pointing at a commit in the gh-pages branch of this repo. To fully deploy changes here to production for use in Grist, you need to:
- Run
npm installin the root of this repo. - Commit and push changes to this repo. It doesn't have to be in the main branch, but an actual commit is important for reference.
- Run
npm run deployto build and push to thegh-pagesbranch. The commit message will contain the commit hash of the commit in step 1. You can use https://gristlabs.github.io/jupyterlite-widget/lab/index.html to test the changes in a Grist doc. - In the
grist-widgetrepo, rungit submodule update --remote --initto update the submodule to the latest commit in thegh-pagesbranch. Commit this update, push, and make a PR. The deploy preview URL can be used to test the changes. - Merge the
grist-widgetPR. This will trigger a deploy to production.
extension/contains the JupyterLab extension that connects the Grist and JupyterLab APIs. See the README there for more details.grist/contains most of the Python code that runs inside the JupyterLite Pyodide and that users can call.package.shpackages the files undergristand puts them infiles/package.tar.gz. JupyterLite picks up the contents offileswhen building, so the package can be downloaded from http://localhost:8000/files/package.tar.gz.package.shis run by bothdev.shand the GitHub Action.extension/src/initKernelPy.tscontains the 'bootstrapping' Python code that the extension runs in the kernel on startup. It downloads the package, extracts it, and imports it.dev.shcleans out old state, does some minimal building for development, and starts a local JupyterLite server.jupyter-lite.jsoncontains configuration for the JupyterLite deployment.
The widget loads many resources at runtime:
- The Grist plugin API (used by all custom widgets) from https://docs.getgrist.com/grist-plugin-api.js
- An optimised, pre-compiled Pyodide distribution from URLs starting with https://cdn.jsdelivr.net/pyodide/v0.24.0/pyc/
- Python packages (whether required by the widget itself or imported by the user's code) from https://pypi.org/ (for metadata) and https://files.pythonhosted.org/ (for wheel files containing the actual packages).