Skip to content

Commit 0284546

Browse files
committed
fix(docs): make JupyterLite demo data reliably accessible
Replay #945 on the current LMDB plugin layout so core dpdata imports do not require LMDB-only dependencies. Stage the online notebook and OUTCAR together for robust xeus content mounting, keep the demo portable across JupyterLite working directories, and remove the duplicate notebook heading. Coding agent: ChatGPT Model: GPT-5.6 Sol
1 parent 629b9af commit 0284546

5 files changed

Lines changed: 47 additions & 10 deletions

File tree

.github/workflows/test_import.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,23 @@ jobs:
3333
assert loaded.formula == system.formula
3434
assert loaded.get_nframes() == system.get_nframes()
3535
PY
36+
- name: Test core import without LMDB dependencies
37+
run: |
38+
python -m pip uninstall -y lmdb msgpack
39+
python - <<'PY'
40+
import dpdata
41+
42+
system = dpdata.System(
43+
"tests/poscars/POSCAR.h2o.md", fmt="vasp/poscar"
44+
)
45+
assert system.get_nframes() == 1
46+
47+
try:
48+
dpdata.System("missing.lmdb", fmt="lmdb")
49+
except ModuleNotFoundError as exc:
50+
assert "lmdb" in str(exc)
51+
else:
52+
raise AssertionError(
53+
"LMDB format should require its backend dependencies"
54+
)
55+
PY

docs/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,6 @@ def setup(app):
216216
jupyterlite_contents = "./nb"
217217
jupyterlite_bind_ipynb_suffix = False
218218
jupyterlite_silence = False
219+
jupyterlite_build_command_options = {
220+
"XeusAddon.mount_jupyterlite_content": True,
221+
}

docs/nb/try_dpdata.ipynb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"metadata": {},
6-
"source": [
7-
"# Try dpdata online"
8-
]
9-
},
103
{
114
"cell_type": "code",
125
"execution_count": null,
@@ -15,6 +8,8 @@
158
"source": [
169
"from __future__ import annotations\n",
1710
"\n",
11+
"from pathlib import Path\n",
12+
"\n",
1813
"import dpdata"
1914
]
2015
},
@@ -24,7 +19,10 @@
2419
"metadata": {},
2520
"outputs": [],
2621
"source": [
27-
"system = dpdata.LabeledSystem(\"OUTCAR\", fmt=\"vasp/outcar\", type_map=[\"O\", \"H\"])"
22+
"outcar = Path(\"OUTCAR\")\n",
23+
"if not outcar.is_file():\n",
24+
" outcar = Path(\"nb/OUTCAR\")\n",
25+
"system = dpdata.LabeledSystem(outcar, fmt=\"vasp/outcar\", type_map=[\"O\", \"H\"])"
2826
]
2927
},
3028
{

docs/try_dpdata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Try dpdata online
22
=================
33

4-
.. retrolite:: nb/try_dpdata.ipynb
4+
.. notebooklite:: nb/try_dpdata.ipynb

dpdata/plugins/lmdb.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
from __future__ import annotations
22

33
from dpdata.format import Format
4-
from dpdata.formats.deepmd.lmdb.format import LMDBFormat
4+
5+
try:
6+
from dpdata.formats.deepmd.lmdb.format import LMDBFormat
7+
except ModuleNotFoundError as exc:
8+
if exc.name not in {"lmdb", "msgpack"}:
9+
raise
10+
11+
_lmdb_import_error = exc
12+
13+
class LMDBFormat(Format):
14+
"""Placeholder used when the LMDB backend dependencies are unavailable."""
15+
16+
def __init__(self, *args, **kwargs) -> None:
17+
raise ModuleNotFoundError(
18+
"The deepmd/lmdb format requires the 'lmdb' and 'msgpack' packages."
19+
) from _lmdb_import_error
20+
521

622
# Canonical name; ``lmdb`` is kept as a backward-compatible alias.
723
Format.register("deepmd/lmdb")(LMDBFormat)

0 commit comments

Comments
 (0)