diff --git a/.gitignore b/.gitignore index 143651c..f714267 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ doc/**/*.ipynb jupyterlite/ !scripts/jupyterlite scripts/jupyterlite/.jupyterlite.doit.db -scripts/jupyterlite/*.json +node_modules diff --git a/scripts/jupyterlite/build.sh b/scripts/jupyterlite/build.sh index 67694de..57f4a59 100644 --- a/scripts/jupyterlite/build.sh +++ b/scripts/jupyterlite/build.sh @@ -11,7 +11,7 @@ export VERSION # Update lockfiles rm -rf node_modules -npm install pyodide@0.24.1 +npm install . node update_lock.js python patch_lock.py rm node_modules/pyodide/*.whl diff --git a/scripts/jupyterlite/extra_packages.json b/scripts/jupyterlite/extra_packages.json new file mode 100644 index 0000000..bb9b704 --- /dev/null +++ b/scripts/jupyterlite/extra_packages.json @@ -0,0 +1,6 @@ +[ + "https://cdn.holoviz.org/panel/1.4.2/dist/wheels/bokeh-3.4.1-py3-none-any.whl", + "https://cdn.holoviz.org/panel/1.4.2/dist/wheels/panel-1.4.2-py3-none-any.whl", + "holonote", + "hvplot" +] diff --git a/scripts/jupyterlite/files/Reset_Jupyterlite.ipynb b/scripts/jupyterlite/files/Reset_Jupyterlite.ipynb new file mode 100644 index 0000000..7f70f88 --- /dev/null +++ b/scripts/jupyterlite/files/Reset_Jupyterlite.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The contents of Panelite are updated on every release, however Jupyterlite caches old edits to files. If you want to reset the storage and **delete all modifications you made to the contents** then run the code below and click the button `Clear JupyterLite local storage` button." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import display, HTML\n", + "display(HTML(\"\"\"\n", + "\n", + "
\n", + "\n", + "\"\"\"))" + ] + } + ], + "metadata": { + "language_info": { + "name": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/scripts/jupyterlite/jupyter_lite_config.json b/scripts/jupyterlite/jupyter_lite_config.json index 6bde4e0..1ba1238 100644 --- a/scripts/jupyterlite/jupyter_lite_config.json +++ b/scripts/jupyterlite/jupyter_lite_config.json @@ -1,6 +1,6 @@ { "LiteBuildConfig": { - "contents": ["../../examples"], + "contents": ["../../examples", "files"], "output_dir": "../../jupyterlite" } } diff --git a/scripts/jupyterlite/package-lock.json b/scripts/jupyterlite/package-lock.json new file mode 100644 index 0000000..f3ad96c --- /dev/null +++ b/scripts/jupyterlite/package-lock.json @@ -0,0 +1,46 @@ +{ + "name": "jupyterlite", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "pyodide": "^0.25.1" + } + }, + "node_modules/base-64": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/base-64/-/base-64-1.0.0.tgz", + "integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg==" + }, + "node_modules/pyodide": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/pyodide/-/pyodide-0.25.1.tgz", + "integrity": "sha512-y0nJ/fLA3bxD2iZRzvVTbP2O+wp4Ewm2wThfV4HF0BytQ6hsoqTJFLNY4usLOcCVBrK8TTWqFqrmsVPzHe4rsw==", + "dependencies": { + "base-64": "^1.0.0", + "ws": "^8.5.0" + } + }, + "node_modules/ws": { + "version": "8.17.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.0.tgz", + "integrity": "sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + } +} diff --git a/scripts/jupyterlite/package.json b/scripts/jupyterlite/package.json new file mode 100644 index 0000000..3343e15 --- /dev/null +++ b/scripts/jupyterlite/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "pyodide": "^0.25.1" + } +} diff --git a/scripts/jupyterlite/patch_lock.py b/scripts/jupyterlite/patch_lock.py index 63c2c25..b3887f7 100644 --- a/scripts/jupyterlite/patch_lock.py +++ b/scripts/jupyterlite/patch_lock.py @@ -14,8 +14,12 @@ def calculate_sha256(file_path): return sha256_hash.hexdigest() +with open("package.json") as f: + package = json.load(f) +pyodide_version = package["dependencies"]["pyodide"].removeprefix("^") + path = "pyodide-lock.json" -url = "https://cdn.jsdelivr.net/pyodide/v0.24.1/full" +url = f"https://cdn.jsdelivr.net/pyodide/v{pyodide_version}/full" with open(path) as f: data = json.load(f) diff --git a/scripts/jupyterlite/update_lock.js b/scripts/jupyterlite/update_lock.js index c07944e..c46e1fa 100644 --- a/scripts/jupyterlite/update_lock.js +++ b/scripts/jupyterlite/update_lock.js @@ -1,23 +1,20 @@ -const { loadPyodide } = require("pyodide") -const fs = require("fs") +const { loadPyodide } = require("pyodide"); +const fs = require("fs"); async function main() { - let pyodide = await loadPyodide() - await pyodide.loadPackage(["micropip"]) + const extra = fs.readFileSync("extra_packages.json", "utf8"); - output = await pyodide.runPythonAsync(` - import micropip - - await micropip.install([ - "https://cdn.holoviz.org/panel/1.3.5/dist/wheels/bokeh-3.3.2-py3-none-any.whl", - "https://cdn.holoviz.org/panel/1.3.5/dist/wheels/panel-1.3.5-py3-none-any.whl", - "https://files.pythonhosted.org/packages/7f/0e/f3e09ad030185c5f2bb03265778699c8f80d7481b1e0abbb2a12c63fe093/holoviews-1.18.2a2-py2.py3-none-any.whl", - "holonote", - "hvplot", - ]) + let pyodide = await loadPyodide(); + await pyodide.loadPackage(["micropip"]); - micropip.freeze() - `) - fs.writeFileSync("pyodide-lock.json", output) + output = await pyodide.runPythonAsync(` +import json +import micropip +extra = json.loads("""${extra}""") +await micropip.install(extra) +micropip.freeze() +`); + fs.writeFileSync("pyodide-lock.json", output); } -main() + +main();