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
extension
folder, runjlpm install
, thenjlpm build
, thenjlpm watch
.jlpm
is a pinned version ofyarn
that is installed with JupyterLab, so you can useyarn
ornpm
instead.jlpm watch
will rebuild the extension when changes are made to the code underextension/src
. For some reason it doesn't work without runningjlpm build
first 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
grist
orextension/src
. Changing.ts
files 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 theextension
folder)pip install -e extension
jupyter labextension develop ./extension
(part ofdev.sh
), maybe with the--overwrite
flag.jlpm build
andjlpm watch
within theextension
folder
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 install
in 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 deploy
to build and push to thegh-pages
branch. 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-widget
repo, rungit submodule update --remote --init
to update the submodule to the latest commit in thegh-pages
branch. Commit this update, push, and make a PR. The deploy preview URL can be used to test the changes. - Merge the
grist-widget
PR. 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.sh
packages the files undergrist
and puts them infiles/package.tar.gz
. JupyterLite picks up the contents offiles
when building, so the package can be downloaded from http://localhost:8000/files/package.tar.gz.package.sh
is run by bothdev.sh
and the GitHub Action.extension/src/initKernelPy.ts
contains the 'bootstrapping' Python code that the extension runs in the kernel on startup. It downloads the package, extracts it, and imports it.dev.sh
cleans out old state, does some minimal building for development, and starts a local JupyterLite server.jupyter-lite.json
contains 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).