Skip to content

Contributing

Local setup

One command syncs the whole workspace — every package installed editable plus the toolchain — into a single .venv:

uv sync --group dev

Day-to-day:

uv run ruff check . --fix     # lint
uv run ruff format .          # format
uv run pyright                # type-check
uv run pytest                 # test all packages
uv run pytest --cov=ahi --cov-report=term-missing

Docs:

uv sync --group docs
uv run mkdocs serve           # http://localhost:8000

Repository layout

ahi-python-packages/
├── pyproject.toml            # workspace root (not published)
├── uv.lock                   # one lockfile for the whole repo
├── packages/
│   ├── ahi-core/  src/ahi/core/   tests/
│   ├── ahi-sql/   src/ahi/sql/    tests/
│   └── ahi-aws/   src/ahi/aws/    tests/
├── docs/                     # this site
├── scripts/
│   ├── publish_order.py      # order packages are uploaded in
│   └── tests/
└── .github/workflows/        # ci · release-please · pages

Each package is a namespace package: the src/ahi/ directory has no __init__.py, so all three contribute to one ahi.* tree.

Adding a new package

  1. mkdir -p packages/ahi-foo/src/ahi/foo packages/ahi-foo/tests
  2. Add packages/ahi-foo/pyproject.toml (copy an existing one; set name, version = "0.1.0", deps). Keep the hatchling packages = ["src/ahi"] block. The name must start with ahi- and match the folder exactly (packages/ahi-foo holds name = "ahi-foo"); CI fails the PR otherwise, because the release job finds each package's files and tag by its folder name.
  3. In the root pyproject.toml, add ahi-foo = { workspace = true } under [tool.uv.sources] and list ahi-foo in the dev group. The first makes uv use the copy in this repo instead of looking on PyPI; the second installs it for tests and type checks.
  4. Register it for releases in both release-please-config.json and .release-please-manifest.json.
  5. Add a docs page under docs/packages/ and a nav entry in mkdocs.yml.
  6. On PyPI, add a pending publisher for ahi-foo (Your account → Publishing → GitHub): owner adaptivehealthintelligence, repository ahi-python-packages, workflow release-please.yml, environment pypi. Without it, the first release fails to upload.
  7. uv sync and you're working.

Releasing

Releases are automated with Release Please in manifest mode with separate PRs, so each package versions independently.

  1. Land changes on main using Conventional Commits — scope them per package. While a package is below 1.0 (all of them, today):

    • fix(ahi-core): correct backoff cap → patch bump (0.2.0 → 0.2.1)
    • feat(ahi-aws): add athena unload helper → patch bump too (0.4.0 → 0.4.1)
    • feat!: ... or a BREAKING CHANGE: footer → minor bump (0.4 → 0.5)

    From 1.0 on, the usual rules apply: fix → patch, feat → minor, breaking → major. (Set by bump-minor-pre-major and bump-patch-for-minor-pre-major in release-please-config.json.)

  2. Release Please opens (or updates) one release PR per changed package with the version bump and changelog.

  3. Merge a release PR. That tags ahi-<pkg>-v<x.y.z>, creates a GitHub Release, then CI builds the package and attaches its wheel + sdist to the Release, uploads them to PyPI (see Publishing to PyPI), and refreshes the Github pages docs site.

Version ranges

When one package depends on another (ahi-aws on ahi-core and ahi-sql), it uses a range up to the next breaking version, never a pin:

"ahi-core>=0.2,<0.3",   # below 1.0: a minor bump means breaking
"ahi-core>=1.2,<2",     # from 1.0: a major bump means breaking

Because new features and fixes never change the part the range is capped on, the range keeps working as the dependency releases. You only change it when:

  • You start using something new from the dependency: raise the lower bound to the version that added it, in the same PR (ahi-sql>=0.2.1,<0.3).
  • The dependency makes a breaking change: check the dependent still works, then raise the upper bound (<0.4, or <3 after 1.0).

When a release PR for the dependency and one for the dependent are both open, merge the dependency's first (see Publishing to PyPI).

One-time repository setup

For the automation to work, an admin needs to:

  • Enable GitHub Pages with Source = GitHub Actions (Settings → Pages).
  • Allow Actions to create releases/PRs (Settings → Actions → Workflow permissions: read/write).
  • Optionally add a CODECOV_TOKEN secret for coverage upload (CI works without it — coverage is then an artifact only).

Publishing to PyPI

The repository stays private, but the packages are published publicly so other repos can depend on them like any PyPI package (ahi-aws>=0.4,<0.5, no index or git source). Anything in a wheel or sdist — the code, tests, README, CHANGELOG.md — is public once uploaded, under the licence each package declares in its pyproject.toml.

Never put private code, data, secrets or internal details in these packages.

How it works. The pypi job in release-please.yml runs after a release PR merges. It downloads that run's wheels and sdists from their GitHub Releases and uploads them with uv publish using trusted publishing: GitHub vouches for the workflow, and the index issues a short-lived upload token for that run. No token is stored anywhere.

Order matters. PyPI doesn't check dependencies on upload, so the job uploads everything from one place, dependencies first, and stops at the first failure. Re-running a failed job is safe: files already on the index are skipped. The order comes from scripts/publish_order.py, which reads each package's dependencies on other workspace packages from its pyproject.toml. CI runs it with --check on every PR, so a misnamed package or packages that depend on each other in a cycle (which has no valid order) fail the PR rather than the release. Keep the layers one-way: ahi-core ← ahi-sql ← ahi-aws, each using only the ones below it.

Each release PR is its own merge and its own run, so the same applies to you: when one package needs a new version of another (say ahi-aws needs a new ahi-sql), merge the dependency's release PR first.

Commit types decide releases. Release Please releases every package whose folder a feat or fix commit touches. For changes that shouldn't release anything (CI, docs, metadata), use ci:, docs: or chore:.

Versions can't be reused. A version number uploaded to PyPI can never be uploaded again, even after deleting it. Fix a bad release with a new version.

Where it publishes. Releases go to PyPI (the job's pypi environment). TestPyPI was used to rehearse the job and isn't published to any more. A package index hosted on Github Pages was also used but is now deleted.

CI

CI is wired to the org's shared building blocks:

  • ci.yml calls shared-workflows/python-ci.yml (lint → type-check → test → coverage).
  • pages.yml uses shared-workflows/detect-changes.yml and the shared-actions Python steps to build the docs.
  • release-please.yml drives versioning and publishing.