Skip to content

๐Ÿ Contributing to CoTyper

First off, thank you for considering contributing to CoTyper โ€” your ideas, bug reports, and code are very much appreciated!

๐Ÿ’ก How to Contribute

You can contribute in several ways:

  • ๐Ÿ’ฌ Open an Issue
    Found a bug? Want to request a feature? Open an issue with as much detail as possible.

  • ๐Ÿ”ง Open a Merge Request
    Have a fix or improvement? Fork the repository and open a merge request against master. Please keep changes focused and small when possible.

  • ๐Ÿงช Add Tests
    If you're fixing or adding features, tests help ensure everything works as expected.

  • ๐Ÿ“š Improve Documentation
    Typo fixes, clarifications, and examples are always welcome!

โš ๏ธ Please Note

While contributions are welcome, there is no guarantee that an issue or merge request will be addressed or merged. This project is maintained on a best-effort basis.

๐Ÿงฐ Development Setup

You need uv. To get started locally:

git clone https://gitlab.opencode.de/lgln/cotyper.git
cd cotyper
uv sync --all-extras            # the package plus the test/dev tools (pytest, ruff, ty, pre-commit)
uv run pre-commit install       # run ruff and the file hygiene hooks on every commit

Before opening a merge request, run the checks CI runs:

uv run pytest --cov                            # tests; fails if coverage drops below 90%
uv run ruff check . && uv run ruff format --check .
uv run ty check --exit-zero-on-warning         # type check src/
uv run --only-group docs mkdocs build --strict # when you touched docs/ or docstrings

๐Ÿ”€ Branches and merge requests

  • master is the only long-lived branch. Create your branch from master, name it <type>/<initials or ticket>/<description> (e.g. fix/ls/config-file-error), and open the merge request against master. <type> is one of feat, fix, docs, refactor, test, ci or chore.
  • Add tests for fixes and features, and update the docs in docs/ when behaviour changes.
  • Add a line to the ## [Unreleased] section of CHANGELOG.md for anything users will notice.
  • Merging does not publish anything. Releases are cut from tags, see below.

๐Ÿš€ Releasing

Releases are triggered by tags, not by merges.

CHANGELOG.md uses the Keep a Changelog format.

  1. In one merge request, bump project.version in pyproject.toml and rename ## [Unreleased] in CHANGELOG.md to ## [<version>] - <date>. Then add a new, empty ## [Unreleased] above it and update the compare links at the bottom. Merge it.
  2. Tag that commit as v<version> and push the tag: git tag v0.14.0 && git push origin v0.14.0.
  3. The tag pipeline runs these jobs:
  4. The usual build and test jobs.
  5. check-release-version, which fails if the tag doesn't match pyproject.toml or if CHANGELOG.md has no section for the version.
  6. pypi-publish, which runs uv build and uv publish.
  7. gitlab-release, which creates the GitLab release for the tag, with the version's CHANGELOG.md section as its notes.

Don't upload builds from a local checkout. The sdist is an allowlist ([tool.hatch.build.targets.sdist] in pyproject.toml); package-check-job fails if it contains anything else or is larger than 500 kB.

pypi-publish authenticates in one of two ways:

  • API token (current setup): if the CI/CD variable COTYPER_PYPI_TOKEN is set, it is used. It must be available to tag pipelines, so either don't mark it protected or protect the v* tags.
  • Trusted publishing (preferred): if the variable is not set, the job exchanges GitLab's OIDC token for a short-lived PyPI token. Support for self-managed GitLab instances is in beta on PyPI. To switch:
  • On PyPI, open the project โ†’ Publishing โ†’ add a GitLab trusted publisher for this project, workflow file .gitlab-ci.yml and environment production.
  • Delete the COTYPER_PYPI_TOKEN variable.

Running the tests

uv run --extra test pytest

CI runs the suite on every supported Python version (3.10 to 3.14) and once with the oldest dependency versions pyproject.toml allows. To reproduce either locally:

uv run --python 3.10 --extra test pytest                                     # one Python version
uv run --isolated --resolution lowest-direct --python 3.10 --extra test pytest  # oldest dependencies

tests/test_examples.py runs --help for every script in examples/ and each of its subcommands, so an example that stops working fails the suite. New examples are picked up automatically.

Coverage is measured for the cotyper package only. The run fails below 90% (fail_under in pyproject.toml):

uv run --extra test pytest --cov --cov-report=term-missing

How the code is organised

A struct_command goes through these modules in src/cotyper/compose/:

Module Job
schema.py Walks the command's signature and flattens model parameters into one BaseModelParameter per option (get_schema).
type_dispatch.py Maps each field annotation to how Typer parses it (process_type_annotation, TYPE_PROCESSORS, register_type_processor).
help_text.py Builds panel names, the model descriptions shown in help panels, and command help text.
rebuild.py Builds the flat-signature function Typer calls, and turns its options back into models at call time (resolve_func_args).
rich_patch.py Shows the model descriptions at the top of help panels.

compose/decompile.py used to hold all of this. It now only re-exports the names, so old imports keep working. New code should import from the modules above.

Lint and type checks

CI runs the same checks as these commands. Their settings live in pyproject.toml ([tool.ruff], [tool.ty]).

uv run --extra dev ruff check .                    # lint
uv run --extra dev ruff format --check .           # formatting
uv run --extra dev ty check --exit-zero-on-warning # type check src/
uv run --only-group docs mkdocs build --strict     # docs, also run on every non-default branch

The pre-commit hooks run on every commit: - ruff check --fix and ruff format; - hygiene hooks that add a final newline, strip trailing whitespace (Markdown line breaks are kept) and check that TOML and YAML files parse.

uv run pre-commit run --all-files runs them over the whole repository. ty reports some known findings as warnings: the runtime-built functions in compose/ trip rules that are relaxed in [tool.ty.rules]. Only errors fail the job.

Building the docs

uv sync --only-group docs
uv run --only-group docs mkdocs serve      # live preview on http://127.0.0.1:8000

The GitLab pages job publishes the docs on every push to the default branch.