Skip to content

Convert the Python monorepo to a uv workspace #8

Closed

Description

@JuroOravec

Current state

The root pyproject.toml is a tooling-only pseudo-project (citry-monorepo, marked non-releasable) with dev/ci extras. There is no [tool.uv.workspace], so uv does not know packages/py/* are projects:

  • packages/py/citry_core (maturin) is installed by hand: uv run maturin develop, both locally and in CI (.github/workflows/py--tests.yml).
  • packages/py/citry (setuptools, pure Python) is installed by hand: uv pip install -e packages/py/citry (docs/codebase.md). The CI workflow currently has no install step for it at all, so its test suite only runs locally.
  • uv.lock covers only the root tooling dependencies; package dependencies are unlocked.

This causes three concrete problems:

  1. uv run is a footgun. A bare uv run re-syncs the environment against the lockfile, which knows nothing about the manually installed editable packages, so it can remove or break them. Everyone has to remember .venv/bin/... or uv run --no-sync.
  2. Test dependencies must be declared twice. A package's test dep (e.g. pytest, and now pydantic for the Kwargs/Slots-as-Pydantic-models tests) lives in the package's [dependency-groups].dev (the semantic owner) AND mirrored in the root extras (the thing the shared venv and CI actually install from). The mirror comments in both pyprojects point at each other, but it is still drift waiting to happen.
  3. Bootstrap is multi-step and undocumented-by-tooling. A fresh clone needs uv sync --extra dev, then maturin develop in citry_core, then uv pip install -e in citry, in the right order.

Proposal

Make the root a uv workspace and let uv sync own the whole environment:

# root pyproject.toml
[tool.uv.workspace]
members = ["packages/py/*"]

[tool.uv.sources]
citry = { workspace = true }
citry-core = { workspace = true }
  • citry's dependency citry-core>=1.3.0 resolves to the workspace member during development (via the source entry) while remaining a normal PyPI range for publishing.
  • Convert the root dev/ci extras to PEP 735 [dependency-groups] (uv installs the dev group by default on uv sync). Keep only genuinely repo-wide tooling there (ruff, mypy, maturin, pre-commit); delete the mirrored test deps (pytest, pydantic) so each package's [dependency-groups].dev is the single declaration.
  • Dev bootstrap becomes: uv sync --all-packages (members install editable automatically). uv run becomes safe, since the lockfile knows about every package.
  • uv.lock then covers all package dependencies, making CI reproducible (uv sync --locked).

The maturin member wrinkle

citry_core builds a Rust extension. With it as a workspace member, uv sync builds it through the maturin PEP 517 backend, but uv's rebuild detection is keyed on package metadata, not Rust sources, so editing crates/** would not trigger a rebuild on the next sync. Two mitigations to evaluate:

  1. [tool.uv] cache-keys on citry_core with file globs over the Rust sources (note they live OUTSIDE the package dir, under crates/), so uv sync rebuilds when Rust changes.
  2. Keep maturin develop as the documented inner-loop command for Rust work, with uv sync handling everything else. (Either way, keep the docs/codebase.md note that benchmarking needs --release; check what profile the PEP 517 editable build uses, since a debug build silently skewed benchmarks once already.)

Migration steps

  1. Add the workspace + sources tables to the root pyproject; commit the citry package's pyproject (currently untracked) so it can be a member.
  2. Move mirrored test deps out of the root extras; convert extras to dependency-groups.
  3. Solve the citry_core rebuild story (cache-keys vs documented maturin develop); verify the editable build profile.
  4. uv lock, commit the expanded uv.lock.
  5. Update CI (py--tests.yml): uv sync --locked --all-packages --group ci, drop the manual maturin step if cache-keys covers it (keep Swatinem/rust-cache), then uv run --no-sync pytest. This also closes the gap where the citry package's tests do not run in CI. Consider pinning the uv version once the lockfile carries this much weight.
  6. Update docs/codebase.md (dev setup, running tests) and remove the mirror comments from both pyprojects.
  7. Verify the release flows still work per package: maturin publish for citry_core (tag-driven workflow), uv build --package citry for the pure-Python package.

Acceptance criteria

  • Fresh clone: uv sync --all-packages produces a venv where every packages/py/* package imports and uv run pytest collects and passes all package test suites.
  • Bare uv run no longer breaks the environment.
  • Each test dependency is declared exactly once, in the owning package.
  • CI runs the citry package's tests and installs from the lockfile.

Refs: root pyproject.toml, packages/py/citry/pyproject.toml, packages/py/citry_core/pyproject.toml, .github/workflows/py--tests.yml, docs/codebase.md ("Development setup", "Running tests").

Activity

  1. JuroOravec commented on Jun 30, 2026

    @JuroOravec
    MemberAuthor

    Implemented in 08570f6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions