Skip to content

Use project-pinned uv and check min version in prek hooks#65531

Merged
potiuk merged 5 commits intoapache:mainfrom
potiuk:uv-version-check-in-prek-hooks
Apr 20, 2026
Merged

Use project-pinned uv and check min version in prek hooks#65531
potiuk merged 5 commits intoapache:mainfrom
potiuk:uv-version-check-in-prek-hooks

Conversation

@potiuk
Copy link
Copy Markdown
Member

@potiuk potiuk commented Apr 20, 2026

Prek hooks that invoke uv (directly from the mypy local runner or indirectly via breeze) now:

  • Prefer uv from the project's main .venv/bin/uv over whatever uv is on PATH, so the uv version used to sync and run mypy is pinned by the project. uv is already part of the dev group via apache-airflow[all], so a regular uv sync installs it. The mypy local runner falls back to uv on PATH with a warning if .venv/bin/uv is missing.
  • Verify that the uv they are about to invoke meets the minimum declared in [tool.uv] required-version in the root pyproject.toml, and fail fast with upgrade instructions (uv self update / uv sync) if it is older — instead of letting a stale uv produce confusing downstream errors.

Implemented as a manual check (regex parse of pyproject.toml, tuple compare of uv --version) in scripts/ci/prek/common_prek_utils.py; wired into initialize_breeze_prek() so every breeze-calling hook gets it, and called explicitly from the mypy local runner against the selected uv_bin. AGENTS.md and contributing-docs/08_static_code_checks.rst updated to describe both behaviors.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (claude-opus-4-7)

Generated-by: Claude Code (claude-opus-4-7) following the guidelines

Prek hooks that invoke uv (directly or via breeze) now prefer
`.venv/bin/uv` from the project's main virtualenv over PATH uv so the uv
version is pinned by the project, and verify it satisfies the minimum
declared in `[tool.uv] required-version` in the root pyproject.toml. If
the main-venv uv is missing, the mypy local runner falls back to PATH uv
with a warning. An outdated uv fails fast with upgrade instructions
instead of emitting confusing downstream errors.
@boring-cyborg boring-cyborg Bot added area:dev-tools backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch labels Apr 20, 2026
@potiuk potiuk added this to the Airflow 3.2.2 milestone Apr 20, 2026
potiuk added 2 commits April 20, 2026 13:21
`breeze`'s `perform_environment_checks` already validates Docker and
docker-compose versions before running any command; extend it with a
matching `check_uv_version` that reads `[tool.uv] required-version` from
the root `pyproject.toml` and confirms the `uv` on PATH satisfies it,
matching the pattern the prek hooks now use. Users get the same clear
"upgrade uv to X.Y.Z" error from `breeze` commands that they'd see from
a standalone prek hook, instead of a confusing failure deeper in the
shell bootstrap.
`[tool.uv] required-version` is the minimum uv contributors must have
installed, not the exact uv version CI pins to. Bumping it on every uv
release would force every contributor to upgrade uv in lockstep, which
is far more churn than the floor check is worth.

Leave an explicit comment both at the declaration site and in
`scripts/ci/prek/upgrade_important_versions.py` (where `UV_PATTERNS`
could be tempted to pick it up) so a future contributor doesn't wire it
into the automated bump by accident. The breeze/prek uv version checks
already read it dynamically and tolerate a stale floor.
potiuk added 2 commits April 20, 2026 13:37
The uv version check is not docker-specific — it applies to any breeze
entry point that invokes uv, including flows that never talk to Docker.
Move `check_uv_version` and `_read_required_uv_version` from
`docker_command_utils` into the generic `environment_check` module, use
`packaging.version.parse` directly instead of docker-scoped
`compare_version`, and move the unit tests alongside.

`perform_environment_checks` continues to call it after the Docker
checks so the behavior is unchanged.
`[tool.uv] required-version` is bumped manually (by design — see the
comment next to it in pyproject.toml). When it moves, any hard-coded uv
version in tests that represents that floor needs to move too or the
fixtures silently drift.

Add a `sync-uv-min-version-markers` prek hook that reads the current
`required-version` and rewrites any line tagged with a
`# sync-uv-min-version` marker to match. The hook fails (prek
convention) when it makes a change, so the contributor just re-stages.

The existing `check_uv_version` tests carry the marker on their mocked
floor constant so a future bump to `required-version` will propagate
through the marker and keep the success-path assertions in sync.
Copy link
Copy Markdown
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow a lot of code just to check and allow other UV installs.

@potiuk
Copy link
Copy Markdown
Member Author

potiuk commented Apr 20, 2026

Oh, wow a lot of code just to check and allow other UV installs.

Unfortunately - and we would not have to do it if not the parsing issue with uv`s internal version check.

@potiuk potiuk merged commit 0a67541 into apache:main Apr 20, 2026
290 checks passed
@potiuk potiuk deleted the uv-version-check-in-prek-hooks branch April 20, 2026 23:02
@github-actions
Copy link
Copy Markdown
Contributor

Backport failed to create: v3-2-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-2-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 0a67541 v3-2-test

This should apply the commit to the v3-2-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants