# Development This page covers how to set up the repository, check a change, and publish a release. ## Setup ComposeUI uses [uv](https://docs.astral.sh/uv/) and Python 3.9 or later. `.python-version` pins 3.9. Install every backend, because the tests cover Qt, Textual, and the web: ```bash 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 ```bash 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: `qtbot` for Qt, `App.run_test()` for Textual, and the Starlette test client for the web. It runs on `httpx2`, or on `httpx` before Python 3.11, as `httpx2` needs 3.11. - A backend's tests are in `tests/qtcore/`, `tests/textualcore/` or `tests/webcore/`, a module per family of `_renderers/` or per other module, such as `test_session.py`. A folder's `support.py` holds the helpers that several of its modules use, and its `conftest.py` the 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. Its `driver` fixture 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, or `collect_ignore_glob` in `tests/conftest.py` for a folder, as for `tests/qtcore/`. The `without-extras` CI job checks it. - `make test` runs the tests in parallel, a worker per CPU (pytest-xdist). So a test must not depend on the state or the order of another. `pytest` without `-n` runs them one after another. On a machine that runs out of memory with a worker per CPU, set fewer, such as `make test PYTEST_WORKERS=8`. - `tests/conftest.py` turns 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`), call `await app.workers.wait_for_complete()`. For a job, call `main_view.jobs.wait()`. On Qt, use `qtbot.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 as `has_result` under 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 `Button` ignores a click for 0.2 s after a press. - `make slow-test` runs 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/.py`. It doesn't slow Qt's own timers. - `make test` runs Qt offscreen, which has no OpenGL widget for VTK: it leaves out the mesh view's VTK renderer, `qtcore/meshrenderer.py` and `qtcore/widgets/qmesh.py`. `make mesh-test` runs its tests in a window and measures them, on a display: on Linux, X or Wayland, or Xvfb, with Mesa's software OpenGL. CI's `mesh` job runs it on Linux, Windows and macOS, for a change of the mesh view, its tests or its dependencies, and for each push to `main`. - 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 test` sets it. To run one file or test: ```bash 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`, marked `browser`. These tests need the `browser` group and Chromium. Install Chromium once with `uv run --group browser playwright install chromium`, then run `make browser-test`. - Preserve the browser tests' `_no_browser_error` guard. 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](https://hypothesis.readthedocs.io/), checks a rule for many inputs that Hypothesis makes. Use one when two implementations must agree, such as `SqliteSource` or `DataFrameSource` and `ListSource`. 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.py` removes the time limit of each input. On CI (`CI` set), Hypothesis's `ci` profile 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 test` fails when the coverage of lines and branches is below 100% (`fail_under` in `pyproject.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 cover` and 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 only` comment. On Windows, `make.ps1` sets `COMPOSEUI_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 only` comment. On Linux and macOS, the `Makefile` sets `COMPOSEUI_WINDOWS_ONLY`, and coverage leaves these lines out. - `specs/` holds TLA+ specs: models of a design that several threads share, such as `Task`'s repeats in `core/jobs.py` (`RepeatingTasks.tla`), or of a state that events reach in any order, such as the web's Log out in `webcore/routes.py` and `webcore/session.py` (`LogOut.tla`). A spec's `.cfg` file names the properties to check. `make specs` checks 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 `.cfg` also records what checking it finds, in a comment: `\* checked: N distinct states, depth D`. `make specs` fails 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 specs` records runs of the real code, and checks that the spec allows each run (`everystate conform`). `specs/log_out_traces.py` drives 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 specs` downloads everystate once into `specs/vendor/`, which is not committed, its platform in the name. It checks the archive's SHA-256 against the one in the `Makefile` and `make.ps1`. When you change `EVERYSTATE_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](../user-guide/translation.md#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 `