Skip to content

Development

igaurab edited this page Nov 18, 2026 · 2 revisions

Requirements

  • Python 3.13 or newer.
  • uv.

gpython uses Textual for the screen and an IPython kernel in a subprocess for the code.

Run from a checkout

Command Result
./gpython Runs the working copy. It makes the environment on first use
uv run gpython The same
uv tool install --editable . Puts gpython and gpy in ~/.local/bin. They run the working copy from all folders
uv tool update-shell Adds ~/.local/bin to PATH

Source layout

All modules are in src/gpython/.

Application

File Contents
__init__.py The command line
app.py, app.tcss The Textual application and its styles. The : commands
pane.py One notebook window: its cells and its kernel
cell.py One cell
windows.py, manager.py Tabs and split layout; the window manager
keymap.py, help.py The table of all keys; the help screen made from it
config.py The config file
statusbar.py The bottom bar
themes.py, themepicker.py Themes and the theme picker

Editor

File Contents
vim.py The vim editor and the completion popup
exlines.py : commands on cells that have no editor on the screen
digraphs.py The digraph table
textview.py The text page for K, :g and :digraphs

Run cells

File Contents
graph.py Which names each cell defines and uses
kernel.py, prespawn.py The kernel process, through jupyter_client; the early start of the kernel
runs.py, pacing.py One run of cells in batches; the rate of screen updates during a run
runnumber.py The r 6 and g 6 key sequences
concurrency.py, kernel_concurrency.py Concurrent cells, in gpython and in the kernel
kernel_asyncio.py asyncio.run in cells
hints.py Hints below a traceback

Files and formats

File Contents
notebook.py File formats: scripts, # %%, marimo, .ipynb
sidecar.py Cell layout and outputs of plain scripts in ~/.gpython
explorer.py, finder.py The file explorer; the file finder

Output

File Contents
outputs.py Outputs of a cell
images.py, imageview.py Kitty graphics placements; the image viewer
markdown.py, mdimages.py, bigtext.py Markdown cells, their pictures, large headings

Panels

File Contents
outline.py The outline panel
variables.py, debugview.py The variables panel and the pictures of the debugger
kernel_side.py The debugger in the kernel

Environments

File Contents
envs.py, envpicker.py Find, make and change environments; the picker and the install prompt
packages.py, packages.json Import name to package name

Tests

uv run pytest -q
  • The tests run in parallel with pytest-xdist (-n auto is in pyproject.toml).
  • uv run pytest -q -n 0 runs them one after the other. This takes approximately 5 minutes.
  • CI (.github/workflows/test.yml) runs the tests on each push to main and on each pull request.
  • A test examines that each application key is in keymap.py.

Performance

Performance is a requirement. These are the limits:

Measure Limit
A key shows on the screen Less than 10 ms
First frame after start Approximately 0.3 s
A cell move Less than 20 ms of CPU

Procedure for a change to the UI

Apply this procedure when you change app.py, pane.py, cell.py, vim.py, outputs.py or app.tcss.

  1. Run uv run python scripts/bench.py two times. Keep the numbers.
  2. Make the change.
  3. Run the benchmark again.
  4. If first_paint, keys_30_net, moves_30_proc or loaded_60 is worse, find the cause with --profile keys, --profile mount or --profile moves, and correct it.

Do not run a benchmark while the tests run.

Scripts

Script Use
scripts/bench.py The benchmark without a terminal
scripts/ptybench.py Time of a real start in a pseudo-terminal
scripts/memprof.py, scripts/membench.py Memory profile; memory compared with JupyterLab and marimo
scripts/kernelbench.py Time of a round trip to the kernel
scripts/warmbench.py, scripts/workbench.py Start and run-all time compared with JupyterLab and marimo
scripts/eval.sh, scripts/workeval.sh Run the full comparison and draw the charts
scripts/benchchart.py, scripts/workchart.py, scripts/benchmeta.py Draw the charts; record the test conditions
scripts/kitty_probe.py Show how a terminal places kitty graphics

Results are in docs/benchmarks/. The history of the optimizations is in docs/optimizations.md.

Rules for code

  • Do not write comments in code. Use clear names, small functions and docstrings.
  • Longer explanations go in docs/plans/.
  • Import a library where the code first uses it, not at the top of a module. This keeps the start fast.
  • Use uv run python.

Design documents

docs/plans/ contains one plan for each large function, for example 11-full-vim.md and 15-uv-projects.md. docs/plans/README.md is the index. docs/plans/TODO.md contains the open work.

Releases

A release goes through a pull request with a review.

  1. From an up-to-date main, make the branch release/X.Y.Z.

  2. In CHANGELOG.md:

    • Move the [Unreleased] entries below ## [X.Y.Z] - YYYY-MM-DD.
    • Add entries for merged changes that have none.
    • Add the compare link at the bottom.
  3. Set version in pyproject.toml.

  4. Run uv lock and uv run pytest -q.

  5. Commit with the message Release X.Y.Z: <summary> and push.

  6. Open a pull request with the title Release X.Y.Z. Ask the other maintainer for a review.

  7. After the merge, put a tag on the merge commit and push it:

    git switch main && git pull && git tag vX.Y.Z && git push origin vX.Y.Z

The tag starts .github/workflows/publish.yml. The workflow:

  • Builds the package.
  • Uploads it to PyPI through trusted publishing.
  • Makes the GitHub release, with the wheel and the sdist attached.
  • Uses the changelog section of the version as the release notes.

The workflow fails if the changelog has no section for the version.

Clone this wiki locally