Skip to content

Commit

Permalink
Update jupyterlite files (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed May 15, 2024
1 parent 0acdc7f commit a49c689
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ doc/**/*.ipynb
jupyterlite/
!scripts/jupyterlite
scripts/jupyterlite/.jupyterlite.doit.db
scripts/jupyterlite/*.json
node_modules
2 changes: 1 addition & 1 deletion scripts/jupyterlite/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions scripts/jupyterlite/extra_packages.json
Original file line number Diff line number Diff line change
@@ -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"
]
61 changes: 61 additions & 0 deletions scripts/jupyterlite/files/Reset_Jupyterlite.ipynb
Original file line number Diff line number Diff line change
@@ -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",
"<button type=\"button\" id=\"button_for_indexeddb\">Clear JupyterLite local storage</button>\n",
"<div id=\"clear-storage-message\"></div>\n",
"<script>\n",
"window.button_for_indexeddb.onclick = function(e) {\n",
" message = document.getElementById(\"clear-storage-message\")\n",
" message.innerText=\"Running\"\n",
" window.indexedDB.open('JupyterLite Storage').onsuccess = function(e) {\n",
" // There are also other tables that I'm not clearing:\n",
" // \"counters\", \"settings\", \"local-storage-detect-blob-support\"\n",
" let tables = [\"checkpoints\", \"files\"];\n",
"\n",
" let db = e.target.result;\n",
" let t = db.transaction(tables, \"readwrite\");\n",
"\n",
" function clearTable(tablename) {\n",
" let st = t.objectStore(tablename);\n",
" st.count().onsuccess = function(e) {\n",
" console.log(\"Deleting \" + e.target.result + \" entries from \" + tablename + \"...\");\n",
" st.clear().onsuccess = function(e) {\n",
" console.log(tablename + \" is cleared!\");\n",
" }\n",
" }\n",
" }\n",
"\n",
" for (let tablename of tables) {\n",
" clearTable(tablename);\n",
" }\n",
" }\n",
" message.innerText=\"JupyterLite local storage has successfully been reset\"\n",
"};\n",
"</script>\n",
"\"\"\"))"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion scripts/jupyterlite/jupyter_lite_config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"LiteBuildConfig": {
"contents": ["../../examples"],
"contents": ["../../examples", "files"],
"output_dir": "../../jupyterlite"
}
}
46 changes: 46 additions & 0 deletions scripts/jupyterlite/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions scripts/jupyterlite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"pyodide": "^0.25.1"
}
}
6 changes: 5 additions & 1 deletion scripts/jupyterlite/patch_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 15 additions & 18 deletions scripts/jupyterlite/update_lock.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit a49c689

Please sign in to comment.