Skip to content

Commit 27fce86

Browse files
authored
Guard against uv.lock drift (#208)
Add a pre-commit hook to ensure the lockfile has been updated with any dependency changes. Likewise, create a nox session to do the same. This combination will help ensure the uv.lock file is correct even when pushed before updating. pre-commit-ci can auto-fix this.
1 parent 5d47939 commit 27fce86

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ repos:
1010
- id: trailing-whitespace
1111
- id: end-of-file-fixer
1212
- id: mixed-line-ending
13+
14+
# Ensure the uv.lock file has been updated
15+
- repo: https://github.com/astral-sh/uv-pre-commit
16+
rev: 0.8.7
17+
hooks:
18+
- id: uv-lock

CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ pre-commit.
5959
uvx nox -s dev
6060
```
6161

62+
### Validate uv.lock
63+
64+
```console
65+
uvx nox -s lock
66+
```
67+
6268
### Run tests and display coverage
6369

6470
```console
@@ -68,7 +74,7 @@ uvx nox -s test
6874
Passing extra arguements to pytest:
6975

7076
```console
71-
uvx nos -s test -- -vvv -x --full-trace
77+
uvx nox -s test -- -vvv -x --full-trace
7278
```
7379

7480
### Run linters

noxfile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# Define the default sessions run when `nox` is called on the CLI
3232
nox.options.default_venv_backend = "uv"
33-
nox.options.sessions = ["format", "lint", "test"]
33+
nox.options.sessions = ["lock", "format", "lint", "test"]
3434

3535
# All linters and formatters are run with `uv run --active`
3636
LINTERS: list[tuple[str, ...]] = [
@@ -123,6 +123,12 @@ def build_artifacts(session: nox.Session) -> None:
123123
session.run("uv", "build")
124124

125125

126+
@nox.session(name="lock", python=False)
127+
def validate_lock_file(session: nox.Session) -> None:
128+
"""Ensure the uv.lock file exists and is aligned with dependencies."""
129+
session.run("uv", "lock")
130+
131+
126132
@nox.session(name="upgrade", python=False)
127133
def upgrade_dependencies(session: nox.Session) -> None:
128134
"""Upgrade all versions of all dependencies."""

0 commit comments

Comments
 (0)