Development¶
This page covers how to set up the repository, check a change, and publish a release.
Setup¶
ComposeUI uses uv and Python 3.9 or later. .python-version
pins 3.9. Install every backend, because the tests cover Qt, Textual, and the web:
uv sync --group dev --all-extras # extras: pyside6, tui (Textual), web (Starlette), report, mesh, vtk, terminal-images, reload
Always run the tools through uv run or the make targets, never a global Python. For
Textual’s console (textual console), add --group textual-dev. It is not in dev: it
installs Textual, which the tests without extras must not find.
Run make hooks once in a clone. It sets git’s core.hooksPath to .githooks/, whose hooks
check a commit’s branch and message against the rules of AGENTS.md (“Commits”).
Commands¶
make lint # ruff format + ruff check --fix
make mypy # mypy on composeui, examples and tests, Qt binding resolved to PySide6
make typecheck # mypy on source + tests; Pyright, Pyrefly and ty on tests
make pyright pyrefly ty # individual test checkers
make test # pytest in parallel, with coverage (browser tests excluded)
make slow-test # the tests three times, one side of their races late each time
make mesh-test # the mesh view's tests with VTK, on a display (not offscreen)
make hooks # git's hooks of .githooks/ in this clone
make browser-test # the web backend in headless Chromium (tests/test_browser.py, Playwright)
make translations # each app's catalogs against the text it translates
make js-check # the page's scripts against their JSDoc types (TypeScript's compiler)
make specs # the TLA+ specs of specs/, and the code's runs against them, in everystate
make check # lint + mypy + translations + js-check
make all # clean + check + test
make css # rebuild webcore/static/app.css after changing classes in webcore
make web-deps # download htmx, uPlot, Cally, deck.gl and vtk.js at pinned versions (commit them)
make docs # build the documentation site into docs/_build/html
make screenshots # the screenshots of the examples guide, on every backend
On Windows without make, use the matching targets in make.ps1. To run the same checks as
the Windows job in CI, run .\make.ps1 translations test. The Linux check job runs
make mypy. The browser job runs make js-check. Locally, make check includes both.
In PowerShell, pass EXAMPLES as -Examples pipeform, batman, TAILWIND_PLATFORM as
-TailwindPlatform, TSC_PLATFORM as -TscPlatform, EVERYSTATE_PLATFORM as
-EverystatePlatform, PYTEST_WORKERS as -Workers, and SLOW_TESTS as -SlowTests.
When you change a target in the Makefile, change it in make.ps1 too:
tests/test_code_rules.py checks that both have the same targets and translated apps.
make mypy checks source, examples, and tests together. It installs the browser group and
all extras so every test import resolves; Chromium is not needed. The other checker targets
also install the typecheck group. Use an individual target to run one checker, or
run make typecheck to run all four.
The browser group includes Playwright. The locked version of its greenlet dependency
has no prebuilt wheel for Python 3.9 on Windows x64. To install that group on this platform,
use Python 3.13, as the browser job does, or use a C++20 compiler to build greenlet.
Run the examples with uv run python -m examples.pipeform --backend qt, or textual, or
web.
Tests¶
Every behavior change needs a test in tests/.
Backend tests exercise real rendered widgets:
qtbotfor Qt,App.run_test()for Textual, and the Starlette test client for the web. It runs onhttpx2, or onhttpxbefore Python 3.11, ashttpx2needs 3.11.A backend’s tests are in
tests/qtcore/,tests/textualcore/ortests/webcore/, a module per family of_renderers/or per other module, such astest_session.py. A folder’ssupport.pyholds the helpers that several of its modules use, and itsconftest.pythe fixtures.A rule that every backend follows, such as “a field reports the user’s text, not the text code sets”, is tested once in
tests/contracts/, a module per family. Itsdriverfixture runs each test on each backend, through a driver per backend that works the real widgets. A rule that one backend alone can break, such as an order of a toolkit’s events, stays in that backend’s folder.The rule that a view’s signals report the user’s changes only is moving into
tests/contracts/, a family at a time. Families moved: inputs, controls. For a view in a moved family, test the rule there, not in each backend’s folder.A test of an optional backend skips without its extra:
pytest.importorskip(...)on a module that only the extra installs, orcollect_ignore_globintests/conftest.pyfor a folder, as fortests/qtcore/. Thewithout-extrasCI job checks it.make testruns the tests in parallel, a worker per CPU (pytest-xdist). So a test must not depend on the state or the order of another.pytestwithout-nruns them one after another. On a machine that runs out of memory with a worker per CPU, set fewer, such asmake test PYTEST_WORKERS=8.tests/conftest.pyturns off automatic garbage collection, and collects on the main thread after each test. PySide can crash when a job’s thread collects a main view that a test dropped.A test that reads what a worker thread or a job does waits for that work, not for a fixed number of pauses. After a Textual file action (Open, Save, Save As,
PickFileAction), callawait app.workers.wait_for_complete(). For a job, callmain_view.jobs.wait(). On Qt, useqtbot.waitUntil(...). On the web, read the views only after a request that follows the job’s result (GET /_composeui/jobs). The job’s thread sets a flag such ashas_resultunder the session’s lock, before its reactive methods fill the views. A fixed wait passes on a fast machine and fails on a slow CI runner, such as Windows with Python 3.9.Concurrency coverage must not depend on scheduling. Explicitly arrange and verify the waiting, cancellation, or cleanup state that a test protects. Do not rely on incidental execution, elapsed time, or a fixed number of event-loop turns. Required coverage must remain exercised on platforms where other tests are skipped.
Fix a flaky test from a failure that you cause. Stretch the timer or delay the work that the test races, show that the test then fails each time, and show that the fix passes in the same condition. A fix of a guessed cause lets the failure come back. Toolkits have timers too: a Textual
Buttonignores a click for 0.2 s after a press.make slow-testruns the tests as a slow runner does, three times: with the test’s own steps late, with every thread late, and with every Textual timer late (--slow-runner,tests/slow_runner.py). A test that waits by chance fails there each time, on any machine. Run it on a test that you add or change:make slow-test SLOW_TESTS=tests/<module>.py. It doesn’t slow Qt’s own timers.make testruns Qt offscreen, which has no OpenGL widget for VTK: it leaves out the mesh view’s VTK renderer,qtcore/meshrenderer.pyandqtcore/widgets/qmesh.py.make mesh-testruns its tests in a window and measures them, on a display: on Linux, X or Wayland, or Xvfb, with Mesa’s software OpenGL. CI’smeshjob runs it on Linux, Windows and macOS, for a change of the mesh view, its tests or its dependencies, and for each push tomain.Don’t wait for a value that later work replaces, such as a repeating task’s result or a progress report: hold that work with an event until the test has read the value. On Textual, wait for what a timer or a thread makes with
_wait_until, and click a button that may not take a click yet with_click_laid_out(tests/textualcore/support.py).Qt tests in a headless environment (CI, WSL) need
QT_QPA_PLATFORM=offscreen.make testsets it. To run one file or test:QT_QPA_PLATFORM=offscreen uv run pytest tests/qtcore/test_choices.py -k combobox
What only a browser shows, such as the page’s scripts and htmx swaps, goes in
tests/test_browser.py, markedbrowser. These tests need thebrowsergroup and Chromium. Install Chromium once withuv run --group browser playwright install chromium, then runmake browser-test.Preserve the browser tests’
_no_browser_errorguard. It checks every page in each context for unhandled JavaScript errors and unexpected Content Security Policy (CSP) violations, even when visible assertions pass. An expected exception needs a narrow, explained allowance in its test, not a disabled guard.A property-based test, with Hypothesis, checks a rule for many inputs that Hypothesis makes. Use one when two implementations must agree, such as
SqliteSourceorDataFrameSourceandListSource. Use one also for a rule of a pure function, such as a date read back as it was shown. Do not use one for rendered widgets or the browser: they are too slow for many inputs.Make the inputs from a small set of values, so that cells are often equal, or equal except for their case. Wide random values rarely make the input that fails.
Add each input that found a bug with
@example(...), so that each run tries it.Discard an input (
reject()) only for the reason that the test expects, never for another error.Break the code that the property checks, and make sure that the test fails. Then restore the code.
tests/conftest.pyremoves the time limit of each input. On CI (CIset), Hypothesis’sciprofile tries the same inputs on each run, so a pull request fails for its own change only. A local run makes new inputs on each run.
make testfails when the coverage of lines and branches is below 100% (fail_underinpyproject.toml). Coverage also counts the child processes that the reload tests start. Add a test with each new line. When no test can reach a line, mark it# pragma: no coverand say why in a comment.A line that only POSIX runs, such as the kill of a process that ignores its termination, gets a
# posix onlycomment. On Windows,make.ps1setsCOMPOSEUI_POSIX_ONLY, and coverage leaves these lines out.A line that only Windows runs, such as the threads that read a process’s output, gets a
# windows onlycomment. On Linux and macOS, theMakefilesetsCOMPOSEUI_WINDOWS_ONLY, and coverage leaves these lines out.specs/holds TLA+ specs: models of a design that several threads share, such asTask’s repeats incore/jobs.py(RepeatingTasks.tla), or of a state that events reach in any order, such as the web’s Log out inwebcore/routes.pyandwebcore/session.py(LogOut.tla). A spec’s.cfgfile names the properties to check.make specschecks each spec with everystate, a TLA+ model checker without Java, in every state that the spec can reach (specs/check_specs.py).A spec’s
.cfgalso records what checking it finds, in a comment:\* checked: N distinct states, depth D.make specsfails when the checker finds other numbers. Change the line with the spec. A checker that misses states would pass a broken spec: the numbers show it.Then
make specsrecords runs of the real code, and checks that the spec allows each run (everystate conform).specs/log_out_traces.pydrives the web’s Log out with Starlette’s test client, and logs the session’s state after each request with the spec’s variable names. A run that the spec doesn’t allow means that the spec no longer describes the code, which model checking alone can’t see. When the spec’s variables change, or the code that the recorder reads, change the recorder too.make specsdownloads everystate once intospecs/vendor/, which is not committed, its platform in the name. It checks the archive’s SHA-256 against the one in theMakefileandmake.ps1. When you changeEVERYSTATE_VERSION, change the SHA-256 of each platform in both files. CI then checks the specs with TLC too, TLA+’s first model checker: it must find the same numbers.
Translations¶
make translations runs composeui translations on each app in TRANSLATED_MAIN_VIEWS of the
Makefile, with --strict: an unused entry fails too. make.ps1 has the same list in
$TranslatedMainViews. When you translate a new app, add its main view to both. See
Checking the catalogs.
Styles of the web backend¶
webcore/static/app.css is built from css/ with Tailwind and daisyUI. When you change
the classes used in webcore, run make css, and commit the built file. make css
downloads the Tailwind CLI and the daisyUI files once, into css/vendor/, which is not
committed. It needs no Node or npm. It checks the SHA-256 of each file against the one in the
Makefile and make.ps1, and fails when they differ. When you change TAILWIND_VERSION or
DAISYUI_VERSION, change the SHA-256 values in both files, and delete css/vendor/. A new
daisyUI version also needs make web-deps, which downloads its license.
The page’s scripts are committed in webcore/static/: htmx, uPlot, Cally, deck.gl, and
vtk.js. uPlot’s stylesheet, css/uPlot.min.css, is committed too. The package then needs no
download, and the page works offline. make web-deps downloads these files from npm at the
versions in the Makefile, and checks their SHA-256. It adds Cally’s license to cally.js
as a comment. It removes the block at the start of vtk.js’s file that adds a <style> element,
which the page’s policy refuses (see The mesh view), and checks
the SHA-256 of the result too.
It keeps the licenses of deck.gl, vtk.js and uPlot beside their scripts, in deckgl.LICENSE,
vtk.LICENSE and uPlot.LICENSE, and daisyUI’s beside app.css, in daisyui.LICENSE.
make js-check downloads TypeScript’s compiler once into js/vendor/, which is not
committed, as make css does Tailwind. It checks the archive’s SHA-256 against the one in the
Makefile and make.ps1. When you change TSC_VERSION, change the SHA-256 values in both
files, and delete js/vendor/.
make web-deps also downloads the declarations of htmx and uPlot into js/, for
make js-check. They don’t go in the package. To update one of them:
Change its version and its SHA-256 in the
Makefileand inmake.ps1.Change its version in the comments of
webcore/page.py.Run
make web-deps css, then the tests, and commit the files.
Code style¶
rufflints withselect = ["ALL"]and a line length of 100.pyproject.tomlhas the ignore list. Fix lint properly rather than addingnoqa. A justified one says why, e.g.# noqa: SLF001 (shared task lifecycle), or in a comment above it.tests/test_code_rules.pyandtests/test_docs.pycheck the rules of this section and of “Architecture” that a script can. Make a new such rule a test, and keep its sentence here for its intent.mypymust pass in strict mode, with the extra checks inpyproject.toml. Fully type-annotate new code: the package shipspy.typed. Mark each method that overrides a base class’s method with@overridefromtyping_extensions, below@propertywhen the method has one.Every Python module starts with
from __future__ import annotations, after its docstring. Ruff enforces it (required-imports, rule I002), andmake lintadds it to a new file. The annotations are then strings:Do not quote them.
Define views at module level, where
attrsresolves their field types. A test may define one in its function to use itstmp_path, typing fields with the module’s names only.Give a
cattrshook its type explicitly, withCONVERTER.register_structure_hook(cls, func), not as a bare decorator, which reads the annotation.Import the type of a view field at run time, not under
TYPE_CHECKING, in the module that defines the view:attrsresolves it there. Ruff checks it:runtime-evaluated-decoratorslistsdefine_viewandattrs.frozen. A module ofcore/_views/thatmain.pyimports cannot nameMainViewin a field. Onlybase.pyhas it, whichmain.pygives it (see Views and renderers).
Stay compatible with Python 3.9. In the annotations that
attrsandcattrsevaluate at runtime, such as view fields, useOptional[...]andUnion[...], notX | Y.In
qtcore, import Qt fromqtpy, never fromPySide6orPyQt*.In a Qt renderer, connect a widget’s signal to a method of the renderer with
self._connect(widget.toggled, self._update_checked), and to a view’s signal withself._relay(self._view.toggled, widget.toggled). Both helpers build aQtSlot(qtcore/qtslot.py): aQObjectchild of the widget, which PySide connects as a Qt slot. PySide searches its whole table of other connections, such as to a lambda, each time a sender is deleted: keep those for a widget that a page has few of, such as a table. EachQtSlottakes time to make, so pass all the methods of one signal to one_connect, in order:self._connect(widget.toggled, self._update_checked, self._view.toggled.call_callbacks). A widget’s own slots are methods of aQObject, and need noQtSlot.A view’s signals report the user’s changes only, so a renderer shows a value set by code without the widget reporting it. Qt blocks the widget’s signals in
refresh_attribute, but not the signals of a child widget, such as the line edit of a date field. Textual sets the value underprevent(...)through a method of the widget, such asComposeInput.set_value.In
webcore, build HTML withMarkup(template).format(...)frommarkupsafe, which escapes every value that is notMarkupitself, never with an f-string.The page’s scripts in
webcore/static/are classic scripts with JSDoc types, each one closure that shares onlywindow.ComposeUI. Put a feature’s code in the script of its domain (page.js,tables.js,charts.js,maps.js).make js-checkmust pass: type what you add, with a JSDoc cast rather than a runtime check that changes what the code does.Put imports that only typing needs under
if TYPE_CHECKING:.Before you change code that holds state over time, write down its states and events, and what each event does in each state. The
state-machinesskill gives the method. It applies to jobs, threads and timers,SqliteDatabaselocking, web sessions and post order,page.jsloaders and swaps, reload, dialogs and screens, or a file being replaced.When you change code that a TLA+ spec of
specs/models, change the spec in the same commit and runmake specs(see Tests). For a design that is not settled yet, you can write the spec before the code: the model checker finds a bad order of events sooner. A new spec adds the module it models to the file filter of thespecsjob inci.yml.The
__all__of each module ofcomposeui.coreis its public API. The API reference shows only these names, andtests/test_docs.pychecks that the docs and the examples import no other name. Add a name that apps use to__all__. The other names, also those that the backends import, can change in any release.Match the comment density of the code around: brief docstrings, and comments that explain why.
Documentation site¶
make docs builds the documentation site with Sphinx and MyST into docs/_build/html.
The site holds the guides, a widget catalog, and an API reference. Install the docs group
and every extra first, because the API reference imports the application module of each
backend:
uv sync --group dev --group docs --all-extras
The guides stay Markdown. MyST builds the Markdown pages in
docs/and its guide directories. A link from a guide to a file outsidedocs/, such as../src/examples/pipeform.py, goes to that file on GitHub (docs/conf.py).The user and technical guides have one page per topic. The first page of each guide lists its pages and their sections. Its
toctreeorders the pages. Add a new page to both lists.The API reference is built from the docstrings. Each page in
docs/api/runsautomodulein an{eval-rst}block, because autodoc writes reStructuredText. In a docstring, single backticks link to the name they hold. When you add a module tocomposeui.core, add its page and its entry indocs/api/index.md.The widget catalog is built from the views. The
widget-catalogdirective (docs/_ext/widgetcatalog.py) lists each view of the modules ofcore/_views/that has a_renderer_key, by module, with the first paragraph of its docstring. A column per backend says whether itsRENDERERShas the key. A new widget, or a new backend, is in the catalog without a change todocs/widgets.md.A warning fails the build, as a broken link or a docstring that autodoc cannot read.
tests/test_docs.pychecks examples and navigation: that the examples import only public names and run, that the contents lists andllms.txtfollow the pages, that the README’s links have a target, and the Markdown’s form. Read its tests for the full list.The screenshots of the examples are taken by a script.
make screenshotsrunsdocs/screenshots.py, which writesdocs/images/<example>-<backend>.pngfor Qt, Textual, and the web, in the light theme. The script sets each example up first, for example by filling in its form or running its job, so every backend shows the same state. It needs thebrowsergroup and Chromium, asmake browser-testdoes. When an example changes what it shows, update its setup in the script, runmake screenshots EXAMPLES=<example>, and commit the images. The script also takesdocs/images/quickstart-web.pngfor the README. It runs the code of the README’s quickstart, so runmake screenshots EXAMPLES=quickstartwhen the quickstart changes.
Continuous integration¶
.github/workflows/ci.yml runs on every pull request and every push to main. It runs
the lint, make mypy, make translations, and make test on Python 3.9 to 3.14, and
make js-check, make browser-test and make docs on Python 3.13. On Windows, it runs
.\make.ps1 translations test, and on macOS make translations test, on Python 3.9 and
3.14. The without-extras job runs the tests on Python 3.9 without any extra, as an app with
one backend installs ComposeUI. The specs job runs make specs. It runs only for a change of
specs/, the modules that the specs model, the Makefile or ci.yml. When the pull request
changes EVERYSTATE_VERSION or its SHA-256, the job also checks the specs with TLC, on the
runner’s Java. When it runs, the “Required checks” job needs it to pass. Run make check test
before you commit.
On a pull request, the repeat job runs each test module that the pull request adds or
changes on Windows with Python 3.9, the slowest runner. It runs each module 20 times, and
fewer when many modules change, down to 3 times. A test that races a timer or another thread
can pass one run by chance. Repeated, it fails there before it reaches main. The job leaves
out tests/test_browser.py, and runs only when a test module changes. The slow job runs the
same modules with make slow-test, on Linux with Python 3.9: there, such a test fails each
time, without luck. The “Required checks” job needs both to pass when they run.
The existing mypy matrix checks source, examples, and tests together. Separate jobs run
make pyright, make pyrefly, and make ty on tests on Python 3.9, matching their
configuration. Failures in these jobs fail the workflow. Run make typecheck locally to
run all four type checkers.
.github/workflows/pull-request.yml runs on each pull request. It runs .githooks/ on its
branch and on each of its commits, and refuses a fix-up commit.
A change of the documentation and the benchmarks’ results only, in docs/, the Markdown files
and benchmarks/results/, runs only the docs job. That job also lints the Python files of
docs/ and runs tests/test_docs.py.
On a push to main or a v* tag, the pages job publishes two versions to GitHub Pages.
Current main is at https://ehmoussi.github.io/composeui/. The latest release is at
https://ehmoussi.github.io/composeui/stable/. The sidebar dropdown selects either version.
A pull request builds both versions without publishing them.
The docs job selects the highest version tag that matches v[0-9]*. It builds that tag’s
guides, widget catalog, and API reference in a separate environment. Only docs/conf.py,
the sidebar templates, and the version selector’s CSS and JavaScript come from the current site.
COMPOSEUI_DOCS_REF sets the version label, repository links, and canonical URL.
COMPOSEUI_DOCS_LATEST_TAG sets the release option. Without it, the build uses the highest
local version tag. A local make docs build defaults to main. Each version generates its
own sitemap.xml with its published URLs. Switching versions opens that version’s home page.
Release¶
.github/workflows/release.yml publishes the package to PyPI with
Trusted Publishing: PyPI trusts the workflow,
so the repository stores no token.
Once, on PyPI and on
TestPyPI, add a publisher for the
project composeui: the owner ehmoussi, the repository composeui, the workflow
release.yml, and the environment pypi (testpypi on TestPyPI). In the repository’s
settings, add the two environments.
To release a version, for example 0.3.0:
On
main, give the version’s entry inCHANGELOG.mdits date (## [0.3.0] - 2026-11-20), and set thecomposeui-versionof the agent skill and its text to the minor version (0.3).Tag
main’s commit, and push the tag. Name the commit: a pull request’s merge makes a new commit, so its branch’s commit is not inmain’s history, and a tag on it would leave the next development versions counting from the previous tag.git fetch origin git tag -a v0.3.0 -m v0.3.0 origin/main git push origin v0.3.0
In the run of the Release workflow, approve the deployment to
testpypi, then the one topypi(Review deployments). Each environment asks for a reviewer.
The tag’s commit must be on main: the workflow stops otherwise. It runs the tests again,
then builds the package. Before it publishes, the workflow
checks that the build’s version is the tag’s, and that CHANGELOG.md has a dated entry for
it; the tests check the skill’s version. Then it publishes to TestPyPI. On Python 3.9 and
3.13, it installs the version from there with the web extra, takes its dependencies from
PyPI, imports each module of composeui.core and runs composeui --help. Only then does it
publish to PyPI, and create the tag’s GitHub release, with the changelog entry as its notes
and the built files. TestPyPI keeps a version that is already there, so a rerun of the tag
does not fail on it.
A manual run of the Release workflow, in the repository’s Actions, is a dry run: it stops
after the install from TestPyPI. It publishes a development version of the commit that it
runs on. setuptools-scm numbers it after the last tag, with its next patch version, such as
0.2.1.dev12 after v0.2.0: only the tag gives the release’s version.