cointoss.notebook¶
notebook
¶
JupyterLab as a woodglue UI at /ui/notebook/, for ad hoc analysis over the Dataset API.
woodglue has no Jupyter kind, so the UI is a command: entry (woodglue.config.UiEntry) that
runs this module with this environment's Python; woodglue fills in {port} and {base_path}
and proxies HTTP and websockets to it. cointoss init prints the entry, ui_entry, rather
than adding it: a kernel runs any code as the service user, so it is opt-in, for dev, and for
the admin only. No Role but the built-in admin should hold view ui:notebook.
The launcher:
- takes the data directory from
--data-dir, else the working directory, which woodglue sets to its own data directory for a UI process, and exports it as$COINTOSS_HOME, so a kernel'scointoss.clientfinds this instance and its admin token; - keeps notebooks in
<data dir>/notebooks/, copying the starter notebook there when it is missing, and never over an edited one; - then becomes JupyterLab (
exec), so woodglue's SIGTERM reaches it directly.
JupyterLab listens on 127.0.0.1 only, with its token and password off, since woodglue has
authenticated the viewer before proxying. allow_remote_access is on because the proxy keeps
the browser's Host, which is not a loopback name when woodglue is reached over the network;
the listening address alone keeps anyone else out.
Needs the notebook extra (JupyterLab and pandas).
jupyterlab_installed()
¶
Whether this environment, the one woodglue runs the launcher with, has JupyterLab.
ui_entry(python=None)
¶
The uis.notebook entry running this install's launcher under python.
python defaults to this environment's, named by absolute path since a systemd unit's
PATH does not hold the virtualenv. The Delegated Token woodglue sends JupyterLab is
limited to calling the cointoss namespace, though no kernel can read it.
>>> ui_entry(Path("/venv/bin/python"))["command"][:3]
['/venv/bin/python', '-m', 'cointoss.notebook']
Source code in src/cointoss/notebook.py
jupyter_args(root, port, base_path)
¶
JupyterLab's arguments: loopback only, no token or password, served under base_path.
>>> args = jupyter_args(Path("/d/notebooks"), 8601, "/ui/notebook")
>>> [a for a in args if "port" in a or "base_url" in a or "ip=" in a]
['--ServerApp.ip=127.0.0.1', '--ServerApp.port=8601', '--ServerApp.port_retries=0', '--ServerApp.base_url=/ui/notebook/']
Source code in src/cointoss/notebook.py
prepare(data_dir)
¶
Create <data_dir>/notebooks/ with the starter notebook in it if missing; return the dir.