|
| 1 | +.. _how-to-matrix-dependency: |
| 2 | + |
| 3 | +Adding or Updating a Matrix Dependency Version |
| 4 | +############################################### |
| 5 | + |
| 6 | +This project tests against multiple versions of certain dependencies (e.g. |
| 7 | +Django). Each version in the matrix gets its own ``[dependency-groups]`` entry |
| 8 | +in ``pyproject.toml``, and ``uv`` produces a single ``uv.lock`` with a separate |
| 9 | +resolution per group via the ``[tool.uv].conflicts`` feature. |
| 10 | + |
| 11 | +The ``test`` group always represents the **current default version** — the one |
| 12 | +used by quality checks, docs builds, and the primary CI matrix entry. Legacy |
| 13 | +versions get their own named groups (e.g. ``django42``). |
| 14 | + |
| 15 | +How it works |
| 16 | +************ |
| 17 | + |
| 18 | +``uv`` normally requires all dependency groups to resolve to a compatible set of |
| 19 | +packages. Declaring groups as conflicting tells ``uv`` they are mutually |
| 20 | +exclusive — it produces a single ``uv.lock`` with independent resolutions for |
| 21 | +each group. ``tox`` then selects the right group per environment via factor |
| 22 | +conditionals, and ``uv-venv-lock-runner`` installs from the lockfile so every |
| 23 | +run is fully reproducible. |
| 24 | + |
| 25 | +Adding support for a new version |
| 26 | +********************************* |
| 27 | + |
| 28 | +Use this process when you want to **add a new version** to the test matrix |
| 29 | +(e.g. start testing against Django 6.0 while still supporting Django 5.2). |
| 30 | + |
| 31 | +1. **Update the default group** in ``pyproject.toml`` to the new version: |
| 32 | + |
| 33 | + .. code-block:: toml |
| 34 | +
|
| 35 | + # Before |
| 36 | + test = [ |
| 37 | + {include-group = "test-base"}, |
| 38 | + "Django>=5.0,<6.0", |
| 39 | + ] |
| 40 | +
|
| 41 | + # After |
| 42 | + test = [ |
| 43 | + {include-group = "test-base"}, |
| 44 | + "Django>=6.0,<7.0", |
| 45 | + ] |
| 46 | +
|
| 47 | +2. **Add a legacy group** for the version being retained: |
| 48 | + |
| 49 | + .. code-block:: toml |
| 50 | +
|
| 51 | + django52 = [ |
| 52 | + {include-group = "test-base"}, |
| 53 | + "Django>=5.0,<6.0", |
| 54 | + ] |
| 55 | +
|
| 56 | +3. **Register the conflict** in ``[tool.uv]`` so ``uv`` knows the groups are |
| 57 | + mutually exclusive: |
| 58 | + |
| 59 | + .. code-block:: toml |
| 60 | +
|
| 61 | + [tool.uv] |
| 62 | + conflicts = [ |
| 63 | + [{group = "test"}, {group = "django42"}, {group = "django52"}], |
| 64 | + ] |
| 65 | +
|
| 66 | +4. **Add a tox factor** for the new legacy version. Update ``envlist`` and add |
| 67 | + a factor conditional to ``dependency_groups``: |
| 68 | + |
| 69 | + .. code-block:: ini |
| 70 | +
|
| 71 | + [tox] |
| 72 | + envlist = py{311,312}-django{52,60},docs,quality,pii_check |
| 73 | +
|
| 74 | + [testenv] |
| 75 | + runner = uv-venv-lock-runner |
| 76 | + dependency_groups = |
| 77 | + django42: django42 |
| 78 | + django52: django52 |
| 79 | + django60: test |
| 80 | +
|
| 81 | +5. **Regenerate the lockfile**: |
| 82 | + |
| 83 | + .. code-block:: bash |
| 84 | +
|
| 85 | + make upgrade |
| 86 | +
|
| 87 | +Retiring a version |
| 88 | +****************** |
| 89 | + |
| 90 | +When a Django version reaches end-of-life and you want to drop it from the |
| 91 | +matrix: |
| 92 | + |
| 93 | +1. Remove the legacy group (e.g. ``django42``) from ``[dependency-groups]``. |
| 94 | +2. Remove it from the ``conflicts`` list in ``[tool.uv]``. |
| 95 | +3. Remove the tox factor conditional line and the envlist entry. |
| 96 | +4. Run ``make upgrade`` to regenerate the lockfile. |
0 commit comments