astral-sh / ruff-pre-commit

A pre-commit hook for Ruff.
Apache License 2.0
802 stars 38 forks source link

Ruff version not fixed? #90

Closed mschwoer closed 1 month ago

mschwoer commented 1 month ago

Hi, not sure if this is a pre-commit, or a ruff, or a ruff-pre-commit issue (or even no issue at all) :-)

I use ruff pre-commit hook locally as well as in the github action pre-commit/action@v3.0.1. This means, it is important that both the local version and the one used by the gh action apply the exact same set of rules (for which employing the exact same ruff version is a prerequisite).

After the latest ruff release v0.4.8, my local and the gh action version apparently starting to use a different ruleset, although I thought I fixed all versions (especially with the rev: v0.4.0, see below).

After changing in .pre-commit.yaml to rev: v0.4.8, the rulesets match again.

I suppose that the rev: v0.4.0 is ignored and the latest version is always used? Unfortuntately I could not proof this, as ruff does not print its verson number when it runs.

thanks for this great tool! cheers, Magnus

Relevant environment: .pre-commit.yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
  rev: v0.4.0
  hooks:
    - id: ruff-format
    - id: ruff
      args: [ '--fix' ]

locally, I use pip install pre-commit==3.7.0 (ruff is not installed directly)

MacBookPro M3, MacOS 14.3 (23D56)

Python 3.11.9 (main, Apr 19 2024, 11:43:47) [Clang 14.0.6 ] on darwin

liamwazherealso commented 1 month ago

The version is fixed, for the 0.4.7 tag you can see the dependencies have changed.

But to verify further you can modify your pre-commit hook to contain a similar hook to the repo.

i.e.

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    # Ruff version.
    rev: v0.4.6
    hooks:
      - id: ruff
        name: ruff
        description: "Run 'ruff' for extremely fast Python linting"
        entry: ruff --version
        language: python
        types_or: [ python, pyi ]
        args: [ ]
        require_serial: true
        additional_dependencies: [ ]
        minimum_pre_commit_version: "2.9.2"

Now when you run it you can see the specified version

$: pre-commit run --all-files -v
ruff.....................................................................Passed
- hook id: ruff
- duration: 0.01s

ruff 0.4.6
charliermarsh commented 1 month ago

Yes that's right -- if you include rev, pre-commit will always use the Ruff version that you marked in rev!