Contributing to Plasma Cylinder

Plasma Cylinder uses pre-commit to enforce the coding standards. This is enforced in CI, but should be set up locally as well.

Minimum system requirements are:

  • Ruby 2.7+

  • Python 3.12+

Cylinder itself runs on Python 3.11. The newer Python is for the tools in requirements.txt, which no longer install on anything older.

After installing the prerequisites, enter the repo directory and create a new python virtual environment using python -m venv venv

Enter the virtual environment using source venv/bin/activate (or .\venv\Scripts\activate on windows)

From within the virtual environment, install the requirements pip install -r requirements.txt

Now, set up the pre-commit hook using pre-commit install

To confirm all of the hooks work, run pre-commit run -a

Before pushing, make sure to run pytest. Running that command will not only perform all of the functional tests, but will also build a test copy of the documentation (this documentation: which you are reading now) and produce a beautiful HTML coverage report. The documentation is written to the docs-preview directory and the coverage report to .repo-reports/coverage. Neither is committed.

Pytest is also run in CI. A failing test will block a merge, so make sure the tests are passing before making a pull request.

What CI does

CI checks your branch and never changes your files. The one commit that it can add is a merge: autoupdate.yaml merges main into an open pull request when main moves ahead of it.

On every pull request, and on every push to main, CI:

  • installs requirements.txt exactly as committed

  • runs every pre-commit hook. Several hooks fix files in place, and a hook that changes a file counts as a failure, so run pre-commit run -a locally and commit the result

  • runs pytest, which requires 100% test coverage and fails on any warning

  • builds this documentation from docs-src, treating warnings as errors

A second job runs the tests on the oldest versions that pyproject.toml allows: Python 3.11 with Werkzeug 3.1.7. It is there so that code which needs something newer fails in CI and not for a user. That job does not install requirements.txt: the tools pinned there need a newer Python, and the Werkzeug pinned there is not the oldest. So the job installs only what the tests need, and leaves the documentation build to the first job.

When you raise the oldest Python or Werkzeug in pyproject.toml, change that job and the reference to match, and for Python the classifiers and the target-version of the linter in pyproject.toml too. A test checks that they all agree. The same test checks that the reference names the first Werkzeug that pyproject.toml does not allow.

A third job runs the tests on Windows and on macOS. Cylinder finds a file by its name, and those systems match a name in any letter case. Windows also has junctions, short names, and drive letters. Some of the tests for those can only run there: the one for junctions is skipped everywhere else. That job does not install requirements.txt either, because the file is compiled on Linux and has no pin for a package that only another system needs. It installs what the tests need, and leaves the documentation build to the first job.

The macOS half of that job runs on main only, after a merge. GitHub is short of macOS runners, and cancels a job that none takes within 15 minutes, which fails the run. Pull requests whose tests had all passed were marked as failed that way. No merge waited for the macOS half, so a pull request loses nothing that held it back. If a change breaks on macOS only, the run on main after the merge is where it shows.

A warning fails the test that it is raised in, because pytest.ini turns every warning into an error. Werkzeug and Python warn about a call for a release or more before they take it away. The third job installs the newest Werkzeug each time it runs, so a call of Cylinder’s that a new release warns about fails there first. Replace the call, and do not silence the warning. The design notes say which calls were replaced, and which one could not be yet.

That job is also how a new Werkzeug is noticed. pyproject.toml allows none that the tests have not run on, and the third job installs the newest there is, whether pyproject.toml allows it or not. Once the tests pass there on a new minor release, raise the upper bound in pyproject.toml and in the reference.

A fourth job runs the tests on each Python between the oldest and the newest that the package is listed for: 3.12, 3.13, and 3.14. What some code does changes with Python, as the design notes record for a dataclass. The job installs what the tests need, with the Werkzeug that requirements.txt pins, so that Python is what differs from the first job. When you list a new Python in pyproject.toml, add it to a job: a test checks that the workflow names every Python that the package is listed for.

A last job, all tests job, passes only when every job before it has passed. Branch protection asks for it, and auto-merge waits only for the checks that branch protection asks for, so a failure in any of those jobs holds up a merge. When you add a job, add it to the needs of that one: a test checks that every job but the one that publishes the documentation is there.

On a push to main, CI also publishes the built documentation to GitHub Pages, together with the coverage and code quality reports and the data behind the badges in the README. None of that generated output is kept in the repository: docs-src is the only copy of the documentation.

Changing dependencies

requirements.txt is generated from requirements.in and is not edited by hand. After changing requirements.in, regenerate it on Linux with the Python version that the first CI job uses, so that it contains the Linux-only packages:

pip-compile requirements.in --generate-hashes --strip-extras --allow-unsafe

On Windows, run that command inside WSL.

Actions in the workflows

A workflow names each action it uses by a commit, with the version that the commit is in a comment:

uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0

A tag such as v5 can be moved to other code by whoever controls the repository of the action. A commit cannot be changed. The image that autoupdate.yaml runs is named by its digest for the same reason, and it is given a personal access token.

automerge.yaml uses that token too, and gives it to no action. It turns on auto-merge by calling gh itself, so that no code from outside this repository is handed the token there.

That workflow runs on pull_request_target, because a pull request from Dependabot is given no Actions secrets under pull_request. GitHub does not start a workflow on pull_request_target in a public repository unless an Actions policy allows the event. The repository has one, named “Allow pull_request_target for the auto-merge workflow”, under Settings, Actions, Policies. It allows the event for automerge.yaml and for no other file. Two things follow:

  • automerge.yaml never runs code from a pull request. On this event a pull request from a fork starts the workflow with the token. The file that runs is the one on main, and it does not check out the pull request.

  • If a run of automerge.yaml ends in a startup failure, look at the policy first. That is how a run ends when its event is not allowed. Another workflow that needs pull_request_target is not covered by the policy.

To move to a newer release of an action, look up the commit of its tag, and change the commit and the comment together:

gh api repos/actions/checkout/commits/v5.1.0 --jq .sha

Working on the documentation

The documentation is the Markdown in docs-src. CI builds it with Sphinx and publishes it to GitHub Pages.

  • One topic per page, and every page under 500 lines. Each page is also published as raw Markdown, and the skill file for AI assistants loads pages one at a time. A page that grows past the limit should be split. A test enforces this.

  • The changelog is two pages. changelog.md has the newest releases. When it nears the limit, move the oldest releases on it to the top of changelog-older.md.

  • docs-src/_extra/SKILL.md is published as it is at the root of the site. When you add a page to the guide, add it to the table of references in that file. A test checks that none is missing.

  • Keep the framework as small as the documentation says. The README and the home page say that Cylinder is less than 450 lines of code. A test counts the lines of src/cylinder.py, leaving out blank lines, comments, and docstrings, and fails when the count reaches the number those pages give.

  • Keep the comments short too. A comment in src/cylinder.py says what the code does, and gives a reason that fits in a line or two. A longer reason goes into the design notes: what was measured, and what was considered and not done. Read that page before you change the file.

  • Run the examples. Code in the documentation should be code that was run.

Releasing

  1. Set __version__ in src/cylinder.py to the new version, such as 0.3.0. It is the number alone, as pip shows it.

  2. In docs-src/changelog.md, rename the Unreleased section to the version number, and its headings from “since” the old version to “in” the new one. Headings must be unique within the page, which is why they carry the version.

  3. Merge that change to main, and wait for the testing workflow to pass there. That run is the only one of the merged commit, and the only one on macOS. The release workflow runs no tests.

  4. Publish a GitHub release whose tag is that version with a v before it, such as v0.3.0, made on main. The release workflow checks that the tag matches __version__, then uploads to Test PyPI and to PyPI. It publishes the commit that the tag is on, whatever branch that is: GitHub has no branch filter for a release.

A tag on its own does not publish anything; the workflow runs when a release is published. The README at that commit becomes the project description on PyPI and cannot be changed afterwards.