Set up Kolibri as a Python monorepo
Overview
Set up the Kolibri repository to act as a Python monorepo so that additional Python plugins and packages can live alongside the main kolibri package. This is a prerequisite for migrating external Kolibri plugins (per #13720) into this repository.
The setup uses uv workspaces for dependency management, places member packages under a top-level python_packages/ directory, and adds a PyPI publishing workflow analogous to the existing npm publishing workflow.
Complexity: High Target branch: develop
Context
PR #14457 migrates Kolibri's Python tooling to uv. uv supports workspaces ([tool.uv.workspace] with member globs), which provides the structural basis for this monorepo setup.
The repository already follows a similar pattern for JavaScript: packages/ contains both published npm packages and private workspace-only packages (distinguished by private: true). Publishing is handled by .github/workflows/npm_publish.yml, which detects version changes per package and publishes them individually. This task creates the Python analogue.
Decisions resolving open questions from #13720:
- All Python member packages live under a single
python_packages/directory (no installer/plugin sub-folders). - Packages to publish to PyPI are listed explicitly in the publishing workflow (mirroring
npm_publish.yml); packages not in the list are workspace-only. - Publishing must use PyPI OIDC trusted publishing (no long-lived API tokens).
- This task does NOT change Kolibri's wheel/installer build pipeline — member packages are independently buildable and published, but are not bundled into the main Kolibri distributions.
The Change
Monorepo structure:
- A new top-level
python_packages/directory holds member packages, each with its ownpyproject.toml. - Root
pyproject.tomldeclares a uv workspace ([tool.uv.workspace]) covering members underpython_packages/. - Member package versions are independent — they do NOT track the main Kolibri version. Compatibility between plugins and Kolibri core is deferred to resolution of #527.
PyPI publishing workflow:
A new GitHub Actions workflow publishes member packages to PyPI when their version changes, modeled on npm_publish.yml:
- Authenticates via PyPI OIDC trusted publishing (no API tokens).
- Lists publishable packages explicitly; packages not in the list are workspace-only.
- Detects version changes per-package and publishes individually.
- Posts to Slack on successful publish (reusing
SLACK_NPM_PACKAGES_WEBHOOK). Messages must explicitly say "PyPI package published" so the unified channel is unambiguous; the existing npm workflow's messages are updated symmetrically to say "npm package published".
CI restructure (cascade for Python tests only):
Adding member-package Python tests on top of the existing matrix would slow PR feedback unacceptably. Split the Python tests into two stages; everything else (lint, wheel build, JS tests) is unchanged.
- Stage 1 — blocking, fast feedback (all in parallel): core Kolibri Python tests on Python 3.10 (the oldest currently non-EOL Python version), Python tests with PostgreSQL.
- Stage 2 — runs after Stage 1 passes, fails fast: the rest of the Python version matrix and per-member-package Python tests. Acts as a safety net for issues unlikely to be caught in Stage 1; gates merge but rarely fails when Stage 1 passes.
Documentation:
Developer docs explain how to add a new member package, how to mark it as publishable in the workflow's package list, and the cascade CI behavior so contributors know which checks gate merge.
First migration:
The kolibri-sync-extras-plugin is migrated into the monorepo as part of this task, serving as the first real member package and validating the structure end-to-end. Git history is preserved by running git filter-repo --to-subdirectory-filter python_packages/kolibri-sync-extras-plugin on a fresh clone of the source repo, then merging into the monorepo with git merge --allow-unrelated-histories (per https://developers.netlify.com/guides/migrating-git-from-multirepo-to-monorepo-without-losing-history/). Historical commit hashes are rewritten — acceptable because the source repo is archived as part of this task.
The kolibri-sentry-plugin migration follows in a separate task using the same procedure.
Out of Scope
- Migrating any other external plugin into the monorepo — handled by per-plugin tasks under #13720.
- Integrating member packages into Kolibri's wheel or installer build pipeline — those continue to ship only the main
kolibripackage. - Plugin/Kolibri compatibility versioning — deferred to #527.
- Cookie-cutter or scaffolding tooling for new packages — out of scope; covered later under #13720 if desired.
Acceptance Criteria
Monorepo structure
- [ ]
python_packages/directory exists at repository root. - [ ] Root
pyproject.tomldeclares a uv workspace ([tool.uv.workspace]) with members underpython_packages/*. - [ ]
uv sync --group devresolves and installs all workspace members. - [ ] Member package versions are independent — no enforcement linking them to the main Kolibri version.
kolibri-sync-extras-plugin migrated
- [ ] Plugin code lives at
python_packages/kolibri-sync-extras-plugin/with its ownpyproject.toml. - [ ] Plugin's existing tests run and pass under the monorepo's CI.
- [ ] Plugin appears in the PyPI publishing workflow's package list.
- [ ] Plugin history is preserved via
git filter-repo --to-subdirectory-filter;git blameon migrated files traces back to the original commits. - [ ] The original
learningequality/kolibri-sync-extras-pluginrepository is archived.
PyPI publishing workflow
- [ ] New workflow file (e.g.
.github/workflows/pypi_packages_publish.yml) publishes member packages to PyPI onpushtodevelopand viaworkflow_dispatch. - [ ] Workflow authenticates using PyPI OIDC trusted publishing — no API tokens stored as secrets.
- [ ]
workflow_dispatchaccepts a target input that publishes to TestPyPI instead of PyPI for testing. - [ ] Publishable packages are listed explicitly in the workflow's
paths:filter andworkflow_dispatchchoice input, mirroringnpm_publish.yml. - [ ] Version-change detection publishes only packages whose version differs from the latest on the target index.
- [ ] Successful publish posts to Slack via
SLACK_NPM_PACKAGES_WEBHOOK. Messages explicitly say "PyPI package published". - [ ] Existing
npm_publish.ymlSlack message is updated symmetrically to say "npm package published".
CI cascade
- [ ] Python tests are split into two stages.
- [ ] Stage 1 runs in parallel: core Kolibri Python tests on Python 3.10, and Python tests with PostgreSQL.
- [ ] Stage 2 runs only after Stage 1 succeeds (
needs:), and runs the remaining Python version matrix plus per-member-package Python tests. - [ ] Stage 2 fails fast — a Stage 2 failure blocks merge.
- [ ] Lint, wheel build, and JS tests continue to run as today, in parallel with Stage 1.
- [ ] Branch protection on
developis updated to require both stages.
Documentation
- [ ] Developer docs explain how to add a new member package (location,
pyproject.tomlrequirements). - [ ] Docs explain how to mark a package as publishable (adding to the workflow's package list).
- [ ] Docs describe the cascade CI structure so contributors know which checks gate merge.
Testing
- [ ] A
workflow_dispatchrun against TestPyPI is performed once before merge to confirm OIDC works end-to-end. - [ ] CI demonstrates the cascade behavior: Stage 2 jobs do not start until Stage 1 succeeds.
- [ ] kolibri-sync-extras-plugin tests pass in the monorepo's CI.
References
- npm publishing workflow (template for PyPI workflow):
.github/workflows/npm_publish.yml - npm publish script:
scripts/npm_publish.sh - uv workspaces documentation: https://docs.astral.sh/uv/concepts/projects/workspaces/
- PyPI OIDC trusted publishing documentation: https://docs.pypi.org/trusted-publishers/
- Plugin/Kolibri compatibility tracking: #527
AI usage
Used Claude Code to draft this issue iteratively from a brief prompt. I drove scope and decisions throughout — selecting the template, resolving open questions from #13720, deciding on uv workspaces, the explicit publish list, OIDC, the CI cascade structure, and folding the kolibri-sync-extras-plugin migration into this task. Claude proposed structure and surfaced gaps; I corrected mistakes (e.g. it dropped the PostgreSQL job from Stage 1 in one revision, which I caught and rewrote) and edited drafts before each was accepted.
Blocked: Python 3.8 support for kolibri-sync-extras-plugin (plan Task 2.2, Step 7)
The plan's "Known Risk" section anticipated that lowering the plugin's requires-python floor from >=3.9 to >=3.6 (matching root Kolibri) might unblock Python 3.8 CI coverage, since the plugin's runtime deps (kolibri, morango, mock, pytest, pytest-django, pytest-env) were confirmed to resolve fine under 3.8.
Reproducing the fix surfaced two additional problems the plan didn't anticipate, both in build tooling, not runtime deps:
- The plugin's
[build-system] requires = ["setuptools>=80"](added during its own uv migration) itself requires Python >=3.9 — no version ofsetuptools>=80supports 3.8. - Lowering that to
setuptools>=64(matching root's own[build-system]) unblocks resolution, but then building on Python 3.8 fails: the plugin'slicense = "MIT"field (PEP 639 SPDX string form) isn't supported by the oldersetuptoolsthat Python 3.8 resolves to —ValueError: invalid pyproject.toml config: project.license.
Fixing #2 requires rewriting the plugin's license metadata to the legacy license = {text = "MIT"} form, which exceeds the plan's scope for this step.
Per the plan's own escalation path, I've reverted requires-python back to >=3.9, <3.15 and left [build-system] requires at >=80 — i.e. Python 3.8 is not supported for this plugin. This means, once Task 4.1 restructures CI:
unit_test_stage2's matrix should drop'3.8'.windows's matrix (currently[3.8]only) needs a different Python version approved for that job.
Could a maintainer confirm:
- Is dropping Python 3.8 from
windows's CI matrix (and fromunit_test_stage2) acceptable, givenkolibri-sync-extras-plugincan't build on it? - Or would you rather see the plugin's
licensemetadata rewritten to the legacy form to keep 3.8 support?
Is dropping Python 3.8 from windows's CI matrix (and from unit_test_stage2) acceptable, given kolibri-sync-extras-plugin can't build on it?
We need to keep Python 3.8 in the Windows CI matrix. However, we do not need to run tests for this plugin on Python version that it does not support - we should just mark tests for the plugin as Python 3.9+ only.
Found a resolution that satisfies both constraints without dropping Python 3.8 anywhere.
Where the failure actually occurs:
uv sync --python 3.8at the repo root (whatunit_test_stage2/windowsrun) fails from the plugin's declaredrequires-pythonalone, before ever attempting to build the plugin.
Why the plugin's requires-python floor is safe to lower:
- Root-level syncs never install the plugin — it isn't a root dependency — so the check is a metadata intersection, not an actual build attempt.
The fix:
- Lowered the declared floor to
requires-python = ">=3.6, <3.15"(matching root).
A second, separate fix was needed:
prek(in the plugin'sdevdependency group) has no build for Python <3.8.uv's lock resolution is universal across the workspace's full declaredrequires-pythonrange, so once the floor dropped to 3.6, resolution failed onprek.- Added
"prek; python_version >= '3.8'". - This matches the marker pattern root Kolibri already uses for the same reason.
Verified locally with uv sync --group test --python 3.8 at the repo root.