Skip to content

Commit 525fec9

Browse files
committed
Use a uv.lock file and uv sync to manage local/CI dependencies
Before this change, dependencies were listed as 'extras' and available we used uv's pip wrapper to install dependencies and pinned the specific versions we use in development and CI environments in pip requirement text files. This change switches to using uv. We now have a single lock file for all dependency groups, and can *sync* our development environments, ensuring unused dependencies are removed. N.B. This change is as small as we can make it to switch to uv and dependency groups. There are further improvements to the contributing guide to bring this project into line with other Kraken projects that might follow later.
1 parent 26cc82b commit 525fec9

8 files changed

Lines changed: 1132 additions & 53 deletions

File tree

.github/workflows/checks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
cache: 'pip'
2323
cache-dependency-path: |
2424
pyproject.toml
25-
requirements/*.txt
25+
uv.lock
2626
tox.ini
2727
2828
- name: Make a virtualenv
@@ -31,7 +31,7 @@ jobs:
3131
- name: Install requirements
3232
run: |
3333
source .venv/bin/activate
34-
make install
34+
python -m pip install --group tox
3535
3636
- name: Run linters
3737
run: |

.github/workflows/release-to-pypi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
tox.ini
4141
4242
- name: Install requirements
43-
run: pip install --requirement requirements/release.txt
43+
run: python -m pip install --group release
4444

4545
- name: Verify version
4646
run: ./scripts/verify-version-tag.py

.github/workflows/tests.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ jobs:
5959
- name: Install requirements
6060
run: |
6161
source .venv/bin/activate
62-
pip install --requirement requirements/prerequisites.txt
63-
uv pip install --requirement requirements/tox.txt
62+
python -m pip install --group tox
6463
6564
- name: Run the tests
6665
run: |

CONTRIBUTING.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## Local development
44

5+
The following tools must be available on your system
6+
to set up a development environment:
7+
8+
- `make`
9+
- [Python]
10+
- [uv]
11+
12+
[Python]: https://www.python.org/downloads/
13+
[uv]: https://docs.astral.sh/uv/
14+
515
### Creating a virtual environment
616

717
Ensure one of the supported Pythons (see README) is installed and used by the `python` executable:
@@ -14,13 +24,10 @@ Then create and activate a virtual environment. If you don't have any other way
1424
environments this can be done by running:
1525

1626
```sh
17-
python3 -m venv .venv
27+
make install
1828
source .venv/bin/activate
1929
```
2030

21-
You could also use [virtualenvwrapper], [direnv] or any similar tool to help manage your virtual
22-
environments.
23-
2431
### Install PostgreSQL
2532

2633
Ensure that a supported version of PostgreSQL (see README) is installed and running on your local machine.
@@ -67,10 +74,8 @@ Package dependencies are declared in `pyproject.toml`.
6774
- _development_ dependencies in the `dev` array in the `[project.optional-dependencies]` section.
6875

6976
For local development, the dependencies declared in `pyproject.toml` are pinned to specific
70-
versions using the `requirements/development.txt` lock file.
71-
You should not manually edit the `requirements/development.txt` lock file.
72-
73-
Prerequisites for installing those dependencies are tracked in the `requirements/prerequisites.txt`.
77+
versions using the `uv.lock` lock file.
78+
You should not manually edit the `uv.lock` lock file.
7479

7580

7681
#### Adding a new dependency
@@ -84,14 +89,14 @@ make install
8489

8590
This will:
8691

87-
1. Build a new version of the `requirements/development.txt` lock file containing the newly added
92+
1. Build a new version of the `uv.lock` lock file containing the newly added
8893
package.
89-
2. Sync your installed packages with those pinned in `requirements/development.txt`.
94+
2. Sync your installed packages with those pinned in `uv.lock`.
9095

9196
This will not change the pinned versions of any packages already in any requirements file unless
9297
needed by the new packages, even if there are updated versions of those packages available.
9398

94-
Remember to commit your changed `requirements/development.txt` files alongside the changed
99+
Remember to commit your changed `uv.lock` files alongside the changed
95100
`pyproject.toml`.
96101

97102
#### Removing a dependency
@@ -107,7 +112,7 @@ To update the pinned versions of all packages run:
107112
make update
108113
```
109114

110-
This will update the pinned versions of every package in the `requirements/development.txt` lock
115+
This will update the pinned versions of every package in the `uv.lock` lock
111116
file to the latest version which is compatible with the constraints in `pyproject.toml`.
112117

113118
You can then run:
@@ -116,14 +121,14 @@ You can then run:
116121
make install
117122
```
118123

119-
to sync your installed packages with the updated versions pinned in `requirements/development.txt`.
124+
to sync your installed packages with the updated versions pinned in `uv.lock`.
120125

121126
#### Updating individual Python packages
122127

123128
Upgrade a single development dependency with:
124129

125130
```sh
126-
pip-compile -P $PACKAGE==$VERSION pyproject.toml --resolver=backtracking --extra=dev --output-file=requirements/development.txt
131+
uv lock -P $PACKAGE==$VERSION --resolver=backtracking
127132
```
128133

129134
You can then run:
@@ -132,6 +137,6 @@ You can then run:
132137
make install
133138
```
134139

135-
to sync your installed packages with the updated versions pinned in `requirements/development.txt`.
140+
to sync your installed packages with the updated versions pinned in `uv.lock`.
136141

137142
[tox]: https://tox.wiki

makefile

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,21 @@ lint:
2727

2828
.PHONY:update
2929
update:
30-
uv pip compile pyproject.toml \
31-
--quiet --upgrade --resolver=backtracking --strip-extras \
32-
--group=dev \
33-
--output-file=requirements/development.txt
34-
uv pip compile pyproject.toml \
35-
--quiet --upgrade --resolver=backtracking --strip-extras \
36-
--group=pytest-in-tox \
37-
--output-file=requirements/pytest-in-tox.txt \
38-
--unsafe-package django
39-
uv pip compile pyproject.toml \
40-
--quiet --upgrade --resolver=backtracking --strip-extras \
41-
--group=release \
42-
--output-file=requirements/release.txt
43-
uv pip compile pyproject.toml \
44-
--quiet --upgrade --resolver=backtracking --strip-extras \
45-
--group=tox \
46-
--output-file=requirements/tox.txt
30+
uv lock --upgrade --resolver=backtracking
4731

4832

4933
# Implementation details
5034
# ======================
5135

52-
# Pip install all required Python packages
36+
# Install all required Python packages
5337
.PHONY:install_python_packages
54-
install_python_packages: install_prerequisites requirements/development.txt
55-
uv pip sync requirements/development.txt
56-
57-
.PHONY:install_prerequisites
58-
install_prerequisites: requirements/prerequisites.txt
59-
pip install --quiet --requirement requirements/prerequisites.txt
38+
install_python_packages:
39+
uv sync --group dev
6040

6141
.PHONY:install_pre_commit
6242
install_pre_commit:
6343
pre-commit install
6444

65-
# Add new dependencies to requirements/development.txt whenever pyproject.toml changes
66-
requirements/development.txt: pyproject.toml
67-
uv pip compile pyproject.toml \
68-
--quiet --resolver=backtracking --strip-extras \
69-
--extra=dev \
70-
--output-file=requirements/development.txt
45+
# Add new dependencies to uv.lock whenever pyproject.toml changes
46+
uv.lock: pyproject.toml
47+
uv lock --upgrade --resolver=backtracking

requirements/prerequisites.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ wheel_build_env = .pkg
1212

1313
pass_env =
1414
DATABASE_URL
15+
dependency_groups = pytest-in-tox
1516
deps =
16-
-r requirements/pytest-in-tox.txt
1717
django42: django>=4.2,<5.0
1818
django50: django>=5.0,<5.1
1919
psycopg2: psycopg2-binary

0 commit comments

Comments
 (0)