Using uv with pre-commit hooks

matmair

matmair

uv is the newest Python developer tool by Astral. It replaces/aims to replace a bunch of different tools around Python packages and is - like ruff - very fast.

I often wait for my pip-compile pre-commit hooks to finish so I am experimenting with replacing them and sharing the preliminary results.

My janky pre-commit hook

There are no official pre-commit hooks for it right now so I am (ab)using my fork of the ruff hooks for a few of my repos, you can find it on GitHub and use it like this in your .pre-commit-config.yaml file:

repos:
-   repo: https://github.com/matmair/ruff-pre-commit
    rev: working 
    hooks:
      - id: pip-compile
        name: pip-compile requirements-dev.in
        args: [requirements-dev.in, -o, requirements-dev.txt, --python-version=3.9]
        files: ^requirements-dev\.(in|txt)$

pre-commit is not keen on me referencing a branch but as this is janky altogether I do not mind.

This hook is very fast, on my M3 MacBook Pro it is nearly impossible to tell if it ran. Even on a bigger project like InvenTree.

Personal reservations around astral

The well-known developer Asotile / Anthony Sottile, who is instrumental in the Python dev-tooling space with important tools like pre-commit, pytest and pyupgrade, recently raised his ethical issues with Astral as a corporation in the OSS space. I am still unsure how I should act concerning those.

The tools Astral builds are very cool but Asotile has a point and he is the right one to raise them with his extensive work on flake8, pyflakes, pre-commit and many other long-lived projects whose years of research were just integrated into ruff.
Not sure how to handle this in my further (non) use of these tools. I felt like this should be mentioned here as it seems to go unnoticed in the current hype.

To be clear: No licenses seem to be broken, it is an ethical question. OSS is much more than code and a few legal texts.