Skip to content

chore: use uv run ruff in pre-commit hooks#436

Open
andreatgretel wants to merge 4 commits intomainfrom
andreatgretel/chore/bump-ruff-precommit
Open

chore: use uv run ruff in pre-commit hooks#436
andreatgretel wants to merge 4 commits intomainfrom
andreatgretel/chore/bump-ruff-precommit

Conversation

@andreatgretel
Copy link
Contributor

@andreatgretel andreatgretel commented Mar 18, 2026

Summary

Replaces the external astral-sh/ruff-pre-commit repo with local language: system hooks that use uv run ruff. This ensures the pre-commit version always matches pyproject.toml and works cross-platform.

Changes

Changed

  • .pre-commit-config.yaml - Replaced astral-sh/ruff-pre-commit (pinned at v0.12.3) with two local hooks using uv run ruff check --fix and uv run ruff format

Fixed

  • Version drift between pre-commit (v0.12.3) and CI (>=0.14.10) that caused divergent ternary-expression formatting
  • Cross-platform compatibility (no longer depends on Unix-only .venv/bin/ paths)

Description updated with AI

The pre-commit hook was pinned at v0.12.3 while pyproject.toml requires
>=0.14.10 (resolving to 0.15.5). This version mismatch caused the
pre-commit formatter to produce output that CI's ruff rejected.
@andreatgretel andreatgretel requested a review from a team as a code owner March 18, 2026 14:56
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 18, 2026

Greptile Summary

This PR replaces the externally-pinned astral-sh/ruff-pre-commit hook (v0.12.3) with two local language: system hooks that invoke uv run ruff check --fix and uv run ruff format. Because uv run resolves ruff from the project's own virtual environment, the pre-commit version now always matches the ruff>=0.14.10 constraint in pyproject.toml, eliminating the formatting/linting divergence that was the root cause of the fix.

  • Version drift eliminated: The old v0.12.3 pin was behind the >=0.14.10 CI requirement; uv run resolves this automatically on every developer machine.
  • Bootstrap dependency resolved: Switching from a hard .venv/bin/ruff path to uv run ruff means no pre-existing virtualenv is required — uv handles environment resolution on first run.
  • Cross-platform compatibility: uv run abstracts away Unix vs Windows binary paths (.venv/bin/ vs .venv\Scripts\), consistent with the project's existing use of uv run throughout AGENTS.md and the Makefile.
  • pass_filenames behavior unchanged: Both hooks correctly default to pass_filenames: true, so only staged Python files are passed to ruff, matching the behaviour of the replaced hooks.

Confidence Score: 5/5

  • This PR is safe to merge — it is a clean, low-risk tooling change that fixes a real version-drift bug with no application logic touched.
  • The change is confined to a single config file, the approach (uv run ruff) is already the canonical pattern used throughout the repo's AGENTS.md and Makefile, and all previously raised concerns (Windows path incompatibility, bootstrap dependency) have been addressed by switching to uv run. No application code is affected.
  • No files require special attention.

Important Files Changed

Filename Overview
.pre-commit-config.yaml Replaces the pinned astral-sh/ruff-pre-commit remote hook with two local language: system hooks that delegate to uv run ruff check --fix and uv run ruff format, ensuring the ruff version always matches pyproject.toml's ruff>=0.14.10 constraint. No functional issues found.

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant PC as pre-commit
    participant UV as uv run
    participant Ruff as ruff (from pyproject.toml)

    Dev->>PC: git commit
    PC->>PC: Run pre-commit-hooks (whitespace, yaml, etc.)
    PC->>UV: uv run ruff check --fix [staged files]
    UV->>Ruff: Resolve ruff>=0.14.10 from uv environment
    Ruff-->>UV: Lint result (fixes applied or errors)
    UV-->>PC: Exit code
    alt Files modified by --fix
        PC-->>Dev: Hook failed — re-stage and recommit
    else Unfixable lint errors
        PC-->>Dev: Hook failed — fix errors manually
    else No issues
        PC->>UV: uv run ruff format [staged files]
        UV->>Ruff: Resolve ruff>=0.14.10 from uv environment
        Ruff-->>UV: Format result
        UV-->>PC: Exit code
        alt Files reformatted
            PC-->>Dev: Hook failed — re-stage and recommit
        else Already formatted
            PC-->>Dev: All hooks passed — commit created
        end
    end
Loading

Last reviewed commit: "Merge branch 'main' ..."

@andreatgretel andreatgretel changed the title chore: bump ruff pre-commit hook to v0.15.5 chore: replace ruff-pre-commit repo with local .venv/bin/ruff hooks Mar 18, 2026
Replaces the external ruff-pre-commit repo with local hooks that run
.venv/bin/ruff directly. This guarantees the pre-commit ruff version
always matches CI (both use the version from pyproject.toml), eliminating
version drift that caused formatting mismatches.
@andreatgretel andreatgretel force-pushed the andreatgretel/chore/bump-ruff-precommit branch from 32dd8a7 to 667d0fe Compare March 18, 2026 15:03
nabinchha
nabinchha previously approved these changes Mar 18, 2026
Replaces .venv/bin/ruff with uv run ruff so the hooks work on
any platform without requiring a pre-existing venv. Also fixes
the misleading "legacy alias" hook name.
@andreatgretel andreatgretel changed the title chore: replace ruff-pre-commit repo with local .venv/bin/ruff hooks chore: use uv run ruff in pre-commit hooks Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants