Skip to content

Commit 7073cba

Browse files
committed
Add docs
1 parent 328d50a commit 7073cba

File tree

7 files changed

+103
-95
lines changed

7 files changed

+103
-95
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ repos:
2727
require_serial: true
2828

2929
# Make sure lock file satisfies dependencies in pyproject.toml.
30-
- id: uv-lock
31-
name: update uv.lock
30+
- id: uv-sync
31+
name: update uv.lock and venv
3232
pass_filenames: false
3333
language: system
34-
entry: uv lock
34+
entry: uv sync
3535
files: ^(uv\.lock|pyproject\.toml)$

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ git init --initial-branch=main /path/to/my-project
4444
copier copy https://github.com/DiamondLightSource/python-copier-template.git $_
4545
```
4646

47-
You can also use it via `pipx run copier` if you have that installed.
47+
You can also use it via `uvx copier` if you have `uv` installed.
4848

4949
<!-- README only content. Anything below this line won't be included in index.md -->
5050

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 23. Adopt uv
2+
3+
Date: 2025-09-22
4+
5+
## Status
6+
7+
Accepted
8+
9+
## Context
10+
11+
[`uv`](https://docs.astral.sh/uv/) appears to be gaining a critical mass of adoption, and adopting the project flow would bring some benefits:
12+
- Much faster venv creation times
13+
- A native lockfile implementation
14+
- A single base image that can install multiple pythons
15+
- Which would allow us to make a single devcontainer base with our feature built in, which would speed up the devcontainer creation time
16+
17+
## Decision
18+
19+
We will adopt this flow.
20+
21+
## Consequences
22+
23+
Docs will need to be updated, especially around lockfile support. Commands will need to be updated slightly for the new version of tox. Work on `renovate` will need to follow as `dependabot` does not support the uv lockfile.

docs/how-to/lint.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ You can run the above checks on all files with this command:
1010
$ tox -e pre-commit
1111
```
1212

13-
Or you can install a pre-commit hook that will run each time you do a `git commit` on just the files that have changed:
13+
The devcontainer will also install a pre-commit hook that will run each time you do a `git commit` on just the files that have changed.
14+
15+
If you want to commit with a failing pre-commit check then you have to:
1416

1517
```
16-
$ pre-commit install
18+
$ git commit --no-verify
1719
```
1820

19-
It is also possible to [automatically enable pre-commit on cloned repositories](https://pre-commit.com/#automatically-enabling-pre-commit-on-repositories). This will result in pre-commits being enabled on every repo your user clones from now on.
20-
2121
## Fixing issues
2222

2323
The typical workflow is:

docs/how-to/lock-requirements.md

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,33 @@
22

33
## Introduction
44

5-
By design this project only defines dependencies in one place, i.e. in the `requires` table in `pyproject.toml`.
5+
Since the move to `uv`, this project natively supports a lockfile. This is a set of "known good" dependencies that the tests are run against, and will be used to create a container if one is built.
66

7-
In the `requires` table it is possible to pin versions of some dependencies as needed. For library projects it is best to leave pinning to a minimum so that your library can be used by the widest range of applications.
7+
## Specifying dependencies
88

9-
When CI builds the project it will use the latest compatible set of dependencies available (after applying your pins and any dependencies' pins).
9+
The source of dependencies is the project's `pyproject.toml`. They can come from:
10+
- Project dependencies (from `[project]` `dependencies =`)
11+
- Dev dependencies (from `[dependency-groups]` `dev =`)
12+
- Transitive dependencies (child dependencies of the above)
1013

11-
This approach means that there is a possibility that a future build may break because an updated release of a dependency has made a breaking change.
12-
13-
The correct way to fix such an issue is to work out the minimum pinning in `requires` that will resolve the problem. However this can be quite hard to do and may be time consuming when simply trying to release a minor update.
14-
15-
For this reason we provide a mechanism for locking all dependencies to the same version as a previous successful release. This is a quick fix that should guarantee a successful CI build.
16-
17-
## Finding the lock files
18-
19-
Every release of the project will have a set of requirements files published as release assets.
20-
21-
For example take a look at the release page for python-copier-template [here](https://github.com/DiamondLightSource/python-copier-template/releases/tag/1.1.0)
22-
23-
There is a single `dev-requirements.txt` file showing as an asset on the release. This has been created using `pip freeze --exclude-editable` on a successful test run using the same version of python as the devcontainer, and will contain a full list of the dependencies and sub-dependencies with pinned versions. You can download this file by clicking on it.
24-
25-
## Applying the lock file
26-
27-
To apply a lockfile:
28-
29-
- copy the requirements file you have downloaded to the root of your repository
30-
- commit it into the repo
31-
- push the changes
32-
33-
The CI looks for a `dev-requirements.txt` in the root and will pass it to pip as a constraint when installing the dev environment. If a package is required to be installed by `pyproject.toml` then `pip` will use the version specified in `dev-requirements.txt`.
14+
Dependencies are loosely specified in `pyproject.toml`, like `sphinx-autobuild` or `pydata-sphinx-theme>=0.12`. They should state a minimum version if you are using features that are added in a specific version. There should be no upper bound by default, only insert one if an upstream release of a dependency breaks your code, and you don't have time to fix it immediately.
3415

3516
## Updating the lockfile
3617

37-
1. Open the repo in a devcontainer
38-
1. Delete dev-requirements.txt
39-
1. Restart your dev container
40-
1. Check the tests run
41-
1. Then run `pip freeze --exclude-editable > dev-requirements.txt`
42-
1. Check the new file into Git
43-
1. Push and merge the changes
18+
When you have updated `pyproject.toml` then run:
19+
```
20+
$ uv sync
21+
```
22+
23+
This will ensure that any new dependencies you add will be placed in the lockfile, and your venv updated to match. It will *not* update any existing dependencies, unless `pyproject.toml` requires a later version.
4424

45-
## Removing dependency locking from CI
25+
This command will be run by [pre-commit](./lint) during a `git commit` and by CI.
4626

47-
Once the reasons for locking the build have been resolved it is a good idea to go back to an unlocked build. This is because you get an early indication of any incoming problems.
27+
To update all dependencies to their latest versions run:
28+
```
29+
uv sync --upgrade
30+
```
4831

49-
To restore unlocked builds in CI simply remove `dev-requirements.txt` from the root of the repo and push.
32+
```{seealso}
33+
[The uv docs on locking and syncing](https://docs.astral.sh/uv/concepts/projects/sync)
34+
```

docs/how-to/update-template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The following steps are recommended to update your project, especially for infre
2626
- for devcontainers
2727
- `ctrl+shift+p` -> `Remote-Containers: Rebuild Without Cache and Reopen in Container`
2828
- for local development
29-
- `pip install -e .[dev] --force-reinstall`
29+
- `uv sync`
3030
- validate your project against the latest tools
3131
- `tox -p`
3232
- fix issues found by the above

0 commit comments

Comments
 (0)