Repository navigation
Update Python test workflow to ensure we install dependencies from uv lockfile - #499
Conversation
| env: | ||
| PYTHONUNBUFFERED: "1" | ||
| UV_SYSTEM_PYTHON: 1 | ||
| UV_FROZEN: 1 |
There was a problem hiding this comment.
This env var ensures that we don't attempt to update the lockfile every time we run a uv command in this workflow. That wouldn't be a big deal, but it would be a waste of time since we wouldn't ever use the new lockfile even if the workflow were to generate one. See the docs for Automatic locking and syncing for more background.
| working-directory: python | ||
| shell: bash | ||
| run: uv pip install .[tests] | ||
| run: uv sync --extra tests |
There was a problem hiding this comment.
This is equivalent to uv pip install ., but it respects the contents of the lockfile (in this case, python/uv.lock).
| shell: bash | ||
| working-directory: python | ||
| run: pytest | ||
| run: uv run pytest |
There was a problem hiding this comment.
Wrapping this pytest call in uv run tells uv to load the virtual environment in the current working directory (in this case, python/) before running the command.
wrridgeway
left a comment
There was a problem hiding this comment.
Thanks for documenting this so well.
As we found in ccao-data/homeval#158, the way we use
uv pip installin thetestworkflow in this repo will cause uv to ignorepython/uv.lockwhen installing dependencies. Instead, uv will decide which dependency versions to install based on the contents ofpython/pyproject.toml, but the dependencies in that config file are not locked to specific versions and hashes like they are inpython/uv.lock.This PR updates the
testworkflow that runs our Python tests to use uv commands that will ensure we use the exact versions of packages pinned inpython/uv.lock. We don't need to update the modeling pipeline itself to use different commands because we use the reticulate uv integration to manage Python dependencies for us. This code has a bit more background:model-res-avm/pipeline/04-interpret.R
Lines 12 to 25 in 3cbee46
Unfortunately, this means that reticulate won't use
python/uv.lockeither. However, this is the recommended way of using the reticulate uv integration, andpy_requiredoesn't include an option to respect a lockfile, so we would need to roll our own solution to start using the lockfile. I think it's better to use the first-party reticulate uv integration and accept the possibility of different package patch versions than it is to roll our own solution and lock down exact package versions, but I'm open to pushback on that decision.We don't need a corresponding condo PR for this res PR because the condo PR doesn't have any Python code, so it doesn't use uv.