Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook to sync pre-commit repos with lockfile versions #23

Open
gresavage opened this issue Oct 31, 2024 · 1 comment
Open

Hook to sync pre-commit repos with lockfile versions #23

gresavage opened this issue Oct 31, 2024 · 1 comment

Comments

@gresavage
Copy link

gresavage commented Oct 31, 2024

An incredibly useful tool I've become accustomed to with Poetry/PDM is the use of a tool/plugin to sync the tagged pre-commit repo versions with the versions of the tools in the lockfile

See: https://github.com/GabDug/sync-pre-commit-lock

  • implemented as plugin for Poetry/PDM that runs when <poetry / pdm> lock is called
  • configured via pyproject.toml

See: https://github.com/floatingpurr/sync_with_poetry | https://github.com/floatingpurr/sync_with_pdm

  • implemented as pre-commit hook written in Python
  • configured with CLAs + .pre-commit-config.yaml

This way, whenever a tool version is updated the developer doesn't have to manually update the pre-commit config to keep the versions in-sync, especially sync pre-commit autoupdate will only update to the latest repo versions, which might conflict with the actual tool versions pinned by UV

Possibly related to: #17

@nathanjmcdougall
Copy link

nathanjmcdougall commented Nov 19, 2024

Personally I'm thinking sync-pre-commit-lock is the best place for this functionality to live:
GabDug/sync-pre-commit-lock#42

Most of the time, the recommendation is not to install a pre-commit tool both in the venv and as a pre-commit hook. But in some cases, it seems unavoidable, e.g. when wanting to use the ruff VS Code extension - it will look at the venv for a ruff install, otherwise it will default to some random version. So in such a case it really needs to be declared both as a dev dependency and a pre-commit hook - so ideally there would be some syncing logic.

As a workaround, in the interim, I am using the hacky technique of using uv run via a system hook. This isn't compatible with the pre-commit.ci bot framework though, also the hook will display a nasty warning when the hooks fails about the fact that the wrong venv is activated. Presumably there are other disadvantages.

-   repo: local
    hooks:
    -   id: ruff-check
        name: ruff-check
        entry: uv run --frozen ruff check --fix
        language: system
        always_run: true
        pass_filenames: false

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

No branches or pull requests

2 participants