From e714c85b5c0b078235419052359c5682fa146c33 Mon Sep 17 00:00:00 2001 From: Preocts Date: Sat, 9 Aug 2025 15:26:12 -0400 Subject: [PATCH] Guard against uv.lock drift 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. --- .pre-commit-config.yaml | 6 ++++++ CONTRIBUTING.md | 8 +++++++- noxfile.py | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 66481f6..04381f5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,3 +10,9 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - id: mixed-line-ending + + # Ensure the uv.lock file has been updated + - repo: https://github.com/astral-sh/uv-pre-commit + rev: 0.8.7 + hooks: + - id: uv-lock diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7c53922..821c2b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,6 +59,12 @@ pre-commit. uvx nox -s dev ``` +### Validate uv.lock + +```console +uvx nox -s lock +``` + ### Run tests and display coverage ```console @@ -68,7 +74,7 @@ uvx nox -s test Passing extra arguements to pytest: ```console -uvx nos -s test -- -vvv -x --full-trace +uvx nox -s test -- -vvv -x --full-trace ``` ### Run linters diff --git a/noxfile.py b/noxfile.py index b83b45a..f9c100d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -30,7 +30,7 @@ # Define the default sessions run when `nox` is called on the CLI nox.options.default_venv_backend = "uv" -nox.options.sessions = ["format", "lint", "test"] +nox.options.sessions = ["lock", "format", "lint", "test"] # All linters and formatters are run with `uv run --active` LINTERS: list[tuple[str, ...]] = [ @@ -123,6 +123,12 @@ def build_artifacts(session: nox.Session) -> None: session.run("uv", "build") +@nox.session(name="lock", python=False) +def validate_lock_file(session: nox.Session) -> None: + """Ensure the uv.lock file exists and is aligned with dependencies.""" + session.run("uv", "lock") + + @nox.session(name="upgrade", python=False) def upgrade_dependencies(session: nox.Session) -> None: """Upgrade all versions of all dependencies."""