emjupy is a multi-file Emacs package, developed with Claude Opus 5.5
and other LLMs. Build a tar and install it:
make package # generates emjupy-i.j.k.tar
then M-x package-install-file RET emjupy-i.j.k.tar
RET, i.j.k being the version.
emjupy needs Emacs 30.1 or later, and websocket 1.15 or later. When
it is installed as a package, the commands you start from are
autoloaded, so no require is needed. They are emjupy-login,
emjupy-open-notebook and emjupy-server-dashboard.
Which Emacs to develop against
The target is Emacs 30.1: it is the minimum the package declares, what
CI runs, and what most users have. make versions says which Emacs is
in use, and whether it is the target.
Source layout
The sources are in src/, one layer per file, and each file requires
only those below it. Reading the code
lists them in that order, says what each holds, and draws the graph of
their requires. emjupy-pkg.el is the package metadata for
make package (MELPA makes its own). emjupy-figure-window.py is the
window that interactive figures open in, and ships with the sources.
The tests are in test/. The unit tests of each file are in
emjupy-FILE-test.el, and what they share is in
emjupy-test-helpers.el. The notebooks they read are in
test_notebooks/.
Code rules
Dependencies run one way
No file calls or names anything defined in a file below it in the table.
A keymap is the exception: it names its commands wherever they are
defined, with a plain quote. A binding is resolved when the key is
pressed, and a keymap reads best whole. There are no declare-function
forms for emjupy's own functions. Each file requires the files whose
functions it uses, and only those. Each file loads on its own:
(require 'emjupy-lsp) works in a fresh Emacs. That is what makes the
rule checkable.
The graph of these requires is in Reading
the code. tools/dependency-graph.py draws it from the code when the
site is built; make dependency-graph draws it alone.
dependencies.dot has every require, for Graphviz.
A lower layer tells a higher one something happened by running a hook:
emjupy-kernel-connected-functionsruns when a kernel attaches.emjupy-modeputs two handlers on it. One asks the kernel where it runs, for the language server. The other tells it the cell width.emjupy-box-width-changed-functions: the width cells are drawn at changed, so the kernel is told.emjupy-comm-functionsruns with each comm message.emjupy-output-owner-functionsis asked which cell owns an output that answers no cell's request. The widgets layer keeps its models from the first. With the second, it claims the output that a moved slider causes.emjupy-widget-view-functions: the drawing layer asks for a widget's controls; the widgets layer answers.
They are wired when a notebook buffer starts – emjupy-mode turns each
layer on – not when a file loads. Only hooks run upward; nothing is
set to one function for a layer below to call. The rest follows from
where things are put:
- A redraw either completes, or is repaired by redrawing from the cells. The redraws that need this are in the redraw layer: a cell's output in place, and every output on a width change. So repairing one is a plain call.
- Undo is in two files, on purpose: Reading the code says why.
- A keymap is defined whole where it is made. The output maps are in the drawing layer, the mode's map is in emjupy-mode.el, and the menu is in emjupy-notebook.el.
- A widget control drawn by the widget-page layer carries the function that opens it, which the widgets layer calls.
Errors
Catch the failure you expect; let the rest through. The package has no
ignore-errors: it hides bugs along with the expected failure.
- A failure with a precondition is checked, not caught. The checks are
window-live-p,buffer-live-p,websocket-pandwebsocket-openp,jsonrpc-running-p, andxref-file-location-p. - A failure found only by trying is caught by its type:
json-error,jsonrpc-errororfile-error. Catchjson-error, the whole family: too-deep nesting and non-UTF-8 bytes are ajson-errorbut not ajson-parse-error. - A failed request to the Jupyter server signals
emjupy-http-error, oremjupy-http-statusfor an error status. Both are children offile-error, which keeps their messages readable.emjupy--http-status-ofextracts the status.emjupy--http-exists-preturns nil for a 404 instead of signalling. - A Contents API path goes through
emjupy--contents-path, never through a bareconcat. A name can hold#or?, soa#b.ipynbwould otherwise be requested, and saved, asa. - Background work that must not abort its command – the language server
warming up as a notebook opens – uses
with-demoted-errors.
Style
Every file starts with the same header. A Lisp file:
;;; emjupy-example.el --- One line saying what it is -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Mathieu Renzo ;; Author: Mathieu Renzo <mrenzo@arizona.edu> ;; Assisted-by: Claude:claude-opus-5.5 and other free-tier LLMs ;; SPDX-License-Identifier: GPL-3.0-or-later ;; This file is not part of GNU Emacs. ;;; Commentary: ;;; Code:
The licence is given by its SPDX identifier alone. Python, shell and the
Makefile carry the copyright and SPDX lines as comments, after any #!.
The code follows the Elisp manual's
Tips
and Conventions and the
Emacs Lisp style
guide. That means: requires and compiler declarations at the top,
Emacs's own indentation, #' for a function that is passed, when and
unless for a single branch, a docstring for every variable with a
value, no commented-out code, and lines of 80 columns. emjupy adds its
own rules:
- Loading a file only defines things. Hooks go in a layer's
-enablefunction, whichemjupy-modecalls. An optional or heavy library, such asxwidgetororgfor LaTeX, is required where it is needed. It is declared at the top, with a comment that says why. - A keymap is a
defvarwhose value builds it whole, never adefine-keyat top level. ;;;###autoloadonly on commands that make sense before emjupy is loaded: logging in, listing, opening, creating, the menu.- A question takes
y-or-n-p. - No advice on another package's functions, but on Eglot's commands:
emjupy-eglot.elsays why. - Every file in sections: user options first, under
;;;; Options, then a;;;;heading per part. Messages start[emjupy]. - A user option goes in its subject's group, defined in emjupy-core.el.
It is
:safeonly if it changes nothing but how a notebook looks or is exported. An option that runs a program, loads code, or reaches a file or host is never:safe. - Comments say why, briefly.
- A line goes past 80 columns only for a string that is long in itself (a URL, a regexp, JSON, a message someone may search for), for a file's first line, or for a test's name.
Words for what is on screen
Function names keep four verbs apart:
- draw: put into the buffer what is not there yet – a cell, its output,
a widget (
emjupy--draw-cell); - redraw: replace what is drawn, in place (
emjupy--redraw-cell-output,emjupy--redraw-notebook, every cell); - render: turn data into what is drawn – faces, an image – touching no
buffer (
emjupy--render-ansi); - refresh: fetch again what may have changed elsewhere – on the server,
in the kernel, the theme (
emjupy-list-refresh).
The drawing layer is still called emjupy-render.el, and two commands
keep the names users know. emjupy-re-render redraws the notebook.
emjupy-refresh-appearance re-reads the theme and redraws.
Makefile targets
| Target | Effect |
|---|---|
make compile |
byte-compile the sources, with src/ first on the load path |
make test |
the unit tests; integration tests skip without a server |
make check |
unit and integration tests; refuses to run without a server |
make lint |
checkdoc and package-lint, both required: make checkdoc, make package-lint |
make docs |
export docs/*.org to the site in html-content/ |
make package |
build emjupy-VERSION.tar |
make install |
install that tar via package-install-file |
make coverage |
line coverage of the suite, as lcov, with a per-file table |
make set-version |
write a new version everywhere: make set-version X.Y.Z (or VERSION=X.Y.Z) |
make check-version |
the version header, emjupy-version and the pkg file agree |
make versions |
which Emacs this is, against the one development targets |
make clean |
remove .elc files and the tar |
make timestamps |
touch every source, to force a full rebuild |
make skill |
the Claude skill in tools/emjupy-dev/, as emjupy-dev.skill |
Continuous integration
Each check runs once per event:
| Event | Runs |
|---|---|
| pull request | build-package.yml: check (lint, the recipe compiled, package, docs), melpazoid, and the tests, unit and live |
push to main |
build-package.yml: check and melpazoid |
push to main changing src/ or test/ |
and coverage.yml: the tests, unit and live, once, instrumented – what fails them fails it |
| tag | release.yml only |
| by hand | set-version.yml, or any of the above from the Actions tab |
Everything that needs only Emacs is one job, check. On main the
tests run once, in coverage.yml. The timing tests are skipped there,
and run on pull requests. The release is one job. It publishes nothing
(release, tarball, site) until all of it passes. It tests what it
ships, because the version commit is often pushed with [skip ci].
Other branches run nothing until a pull request; a newer push cancels a run still going. Build also runs for changes to the docs, the tools, the notebook corpus and the MELPA recipe.
Running everything locally
What CI runs, cheap checks first.
Once: what the checks need
- Emacs 30.1 –
make versionssays whether you have it. websocket.el: an installed copy is found, or name a checkout withexport EMJUPY_WEBSOCKET_DIR=/path/to/emacs-websocket.For the integration tests, a Python environment with the server, a kernel and a language server:
bashpip install jupyter-server ipykernel jupyter-lsp 'python-lsp-server[all]'make lintneeds package-lint:M-x package-install RET package-lint, orPACKAGE_LINT_DIRnaming a checkout. It runs as MELPA runs it, so warnings fail too. It fails without package-lint, and without an archive that lists the dependencies: MELPA, or the oneEMJUPY_PACKAGE_ARCHIVEnames.melpazoid needs a clone and Docker, because it runs in a container to match MELPA:
bashgit clone https://github.com/riscy/melpazoid ~/melpazoid
Every time
make compile # no warnings expected make test # unit tests, about ten seconds make lint # checkdoc and package-lint: nothing expected make check-version # three places agree on the version
The integration tests, against a server of your own:
mkdir -p /tmp/nbroot JUPYTER_TOKEN=abc jupyter server --no-browser --port=8888 --ip=127.0.0.1 \ --ServerApp.root_dir=/tmp/nbroot & EMJUPY_TEST_URL=127.0.0.1:8888 EMJUPY_TEST_TOKEN=abc \ EMJUPY_TEST_ROOT=/tmp/nbroot make check
EMJUPY_SKIP_UNSTABLE=1 leaves out tests tagged :unstable, as CI does.
melpazoid, reading the recipe MELPA will be sent:
RECIPE="$(cat .github/melpa-recipe)" LOCAL_REPO="$PWD" make -C ~/melpazoid
Coverage needs undercover.el and its two dependencies, installed or
checked out:
git clone https://github.com/undercover-el/undercover.el ~/src/undercover git clone https://github.com/magnars/dash.el ~/src/dash git clone https://github.com/rejeep/shut-up.el ~/src/shut-up export EMJUPY_UNDERCOVER_PATH=~/src/undercover:~/src/dash:~/src/shut-up make coverage # prints a per-file table; lcov in coverage/
With the integration variables set it covers the server-facing code
too, as CI runs it. Tests tagged :timing are left out: instrumented,
time means nothing.
Build the docs and run CI's link check, which requires every linked page and anchor to exist:
make docs # then open html-content/index.html python3 tools/check-links.py
The Org sources are checked too, by the test suite, without building the
site. emjupy-test-every-link-in-the-docs-leads-somewhere follows
every internal link to its file, and to the heading it names.
Link to a section by its title: [[*Title]] within a page,
[[file:page.org::*Title]] to another page. There is no CUSTOM_ID to
manage. The site makes each heading's anchor from the slug of its
title, and resolves title links to it. Renaming a heading changes its
anchor, so links to it need the new title.
python3 tools/check-links.py finds any that do not have it.
.github/melpa-recipe must list every file the package ships.
make recipe-check checks it, as CI does: every file the Makefile ships
is listed, nothing listed is missing, and the recipe's files alone, in
an empty directory, byte-compile. Run it after adding a file:
make recipe-check
Compiling one file by hand
M-x byte-compile-file compiles against load-path. If emjupy is also
installed from an archive, (require 'emjupy-core) finds the INSTALLED
copy, and a module added since then is not found. "Cannot open load
file: emjupy-remote" means that, not a fault in the file.
make compile puts src/ first. By hand, put the checkout first on
load-path, or uninstall the package meanwhile.
The tests, the scripts in tools/, emjupy-pkg.el and publish.el say
no-byte-compile: they are not code to load compiled. An install from
git with package-vc, or with use-package :vc, compiles the whole
checkout. Without the mark, such an install reports an error when it
compiles a test.
Tests
Unit tests
The self-contained suite needs only websocket:
make test # which is emacs -batch -Q -l test/emjupy-run-tests.el
websocket comes from load-path, then from EMJUPY_WEBSOCKET_DIR,
then from GNU ELPA. So the suite runs offline too:
EMJUPY_WEBSOCKET_DIR=/path/to/emacs-websocket make test
Integration tests (real server, real kernel, real LSP)
emjupy-integration-test.el runs real Python in a real kernel on a live
Jupyter server. The tests are opt-in: they ert-skip unless the
environment names a running server. They catch what only a live server
shows: an image this Emacs cannot display, a WebSocket URL that drops
its base path, or a saved notebook that no other tool opens.
| Variable | Meaning |
|---|---|
EMJUPY_TEST_URL |
host:port of a running server (the LOCAL end of a tunnel) |
EMJUPY_TEST_TOKEN |
its token |
EMJUPY_TEST_ROOT |
server root dir, for the nbformat-validation test |
EMJUPY_TEST_URL2 |
a SECOND server, for the multi-server tests |
EMJUPY_TEST_TOKEN2 |
its token (defaults to EMJUPY_TEST_TOKEN) |
For the remote path, point EMJUPY_TEST_URL at the local end of an ssh
tunnel:
# server side: jupyter listens only on loopback JUPYTER_TOKEN=abc jupyter server --no-browser --port=8888 --ip=127.0.0.1 # client side: forward a local port through ssh ssh -N -L 18888:127.0.0.1:8888 user@remote-host & EMJUPY_TEST_URL=127.0.0.1:18888 EMJUPY_TEST_TOKEN=abc \ EMJUPY_TEST_ROOT=/path/to/notebook/root make check
The WebSocket language-server tests need jupyter-lsp and
python-lsp-server where the server runs (the pip line above). Those
of the local fallback need a server on this machine's PATH (pylsp,
pyright-langserver or jedi-language-server), and skip without one.
Robustness tests
test/emjupy-robustness-test.el holds tests making their own inputs.
They run with make test, and catch what hand-written tests miss.
Faults found by fuzzing a running notebook that are not yet fixed are issues on GitHub.
| Test | What it tries |
|---|---|
| message order | random interleavings of a kernel's replies and outputs |
| random edits | random sequences of cell commands, invariants after each |
| undo everything | random edits, then undo to the start |
| round-trip | every notebook in test_notebooks/test-corpus/, saved and reloaded |
| hostile content | escape floods, huge SVGs, deep JSON, awkward file names |
| leaks | many sessions; timers, processes, hooks, tables after |
Seeds
Every failure of a randomised test names its run's seed:
Info: EMJUPY_FUZZ_SEED=4, case 5 Info: after (insert-above insert-below delete-char split move-down)
Set it to replay the run; EMJUPY_FUZZ_ITERATIONS sets the cases per
test, by default ten to two hundred:
EMJUPY_FUZZ_SEED=4 EMJUPY_FUZZ_ITERATIONS=500 make test
Shrink a failing sequence before working on it: drop a step, and keep the drop while it still fails.
Expected failures
A test of a known, unfixed fault is marked :expected-result :failed,
with the reason in its docstring. The suite stays green and the fault
stays visible. A fix then shows as an unexpected pass, which is the cue
to remove the mark.
The notebook corpus
tools/make-notebook-corpus.py writes test_notebooks/test-corpus/
with nbformat, so each notebook is valid by Jupyter's own definition.
tools/check-roundtrip.py compares a notebook with emjupy's save of it
(cells, sources, outputs, metadata, attachments), and validates the
save. Without nbformat, the round-trip test checks only that saving
twice changes nothing. Add a new shape to the generator, not by hand.
The generator gives each cell the same id on every run, so the corpus
changes only when the generator does. CI fails if the committed corpus
differs from what the generator writes.
The notebooks next to it are for trying emjupy, and are kept without
outputs; CI checks that with nbstripout --verify.
nbstripout --install makes git strip them as they are committed.
.gitattributes names those notebooks, and not the corpus, whose
outputs are what it tests.
Network faults
tools/faultproxy.py sits between emjupy and the server. On command it
drops connections, stalls, delays, or splits what it forwards. The
emjupy-int-fault-* tests start it in front of the test server, so they
need python3. By hand:
python3 tools/faultproxy.py 127.0.0.1 8888 # prints its port and control port echo stall | nc 127.0.0.1 CONTROL-PORT # or sever, resume, delay 200, chunk 7, reset
Compiled files
Emacs loads a .elc before its .el, newer or not. To see a test fail
without a fix, make clean first, or the test runs the compiled old code.
Test hygiene
A unit test must give the same answer on every machine. Two detections
would vary: the host of an SSH tunnel, read from the process list, and
whether LaTeX renders, which depends on the programs installed.
emjupy-probe-environment governs both. The unit test runner binds it
to nil. A test of the detection itself binds it to t, and stubs what
the detection examines.
- Test the key binding, not only its command. A command bound to
DELalone is not reached in a graphical Emacs, which sends<backspace>. - Do not wrap the action tested in
ignore-errors: the error it swallows may be the failure. - A stub of a function Emacs itself uses calls through for the cases the test is not about.
- Assert invariants rather than mechanisms, which differ between Emacs versions.
Invariants
M-x emjupy-debug-check-invariants reports how a buffer and its cells
disagree. It names the cell, and says whether an overlay is missing,
overlapping, out of order, or detached from its output box, or whether
it shows text that the cell does not hold. In each case, what is
displayed and what would be saved have come apart. Tests call it after
every operation.
Performance
Three tests guard against regressions, not speed:
- work after every command does not grow with the notebook;
- redrawing output does not either: only the cell concerned is redrawn;
- nothing on a path run after a command touches a remote file.
The last matters most: TRAMP blocks Emacs for a round trip, paid on every keystroke if on the per-command path. The test asserts no such calls, not a duration, which would depend on a network. The costs kept small are measured in Language server support.
Releasing and MELPA
Releasing
- Set the version. On GitHub: Actions, "Set version", "Run
workflow", with the new version as
X.Y.Z. The workflow writes the version everywhere the current one is: the;; Version:header,emjupy-version,src/emjupy-pkg.el, and the sample indocs/usage.org. It checks that they agree, and commits. Locally:make set-version X.Y.Z. - Tag that commit with the version, and push the tag. The release
then runs the tests, puts the tarball on the release page, and
publishes the site, all from that commit. Tag it yourself: a tag
that a workflow pushes starts no other workflow. A commit message
with
[skip ci]skips tag pushes too, so tag a commit without it.
The package's own description
C-h P emjupy shows the ;;; Commentary: of src/emjupy.el: what
emjupy is, what it needs, and how to start. It is written for someone
who has just installed it. package.el would otherwise show a README, a
web page of badges and links. So the tarball from make package has no
README, like MELPA's. A package-vc install is the whole checkout, and
shows the README.
The opening paragraph is the same in the Commentary, the README and
docs/index.org; keep it so. The one-line summary is the same in
src/emjupy.el's header and src/emjupy-pkg.el.
Submitting to MELPA
The recipe lists its files, for two reasons. They are in src/, where
MELPA's default :files does not look. They are listed by name, so
that a development file added there does not ship. The tests, in
test/, are not shipped. The recipe is kept at .github/melpa-recipe,
which the melpazoid job reads too:
(emjupy :fetcher github :repo "mathren/emjupy" :files ("src/emjupy.el" "src/emjupy-core.el" "src/emjupy-terminal.el" "src/emjupy-ipynb.el" "src/emjupy-latex.el" "src/emjupy-undo.el" "src/emjupy-faces.el" "src/emjupy-http.el" "src/emjupy-render.el" "src/emjupy-cells.el" "src/emjupy-redraw.el" "src/emjupy-commands.el" "src/emjupy-kernel.el" "src/emjupy-figures.el" "src/emjupy-widgets.el" "src/emjupy-widget-page.el" "src/emjupy-figure-window.py" "src/emjupy-remote.el" "src/emjupy-lsp.el" "src/emjupy-shadow.el" "src/emjupy-eglot.el" "src/emjupy-mode.el" "src/emjupy-save.el" "src/emjupy-notebook.el" "src/emjupy-dashboard.el" "src/emjupy-tramp-open.el"))
Before submitting:
make check # unit and integration tests make lint # checkdoc and package-lint make package # builds the tar
and check that:
- melpazoid reports nothing – its CI job runs it on the recipe above, warnings as errors;
- the tar installs into an empty
package-user-dirandM-x emjupy-modeworks there; - each module loads on its own in a fresh Emacs, which shows an accidental dependency on load order.
