Skip to content

Consider required-version when finding the ruff binary #701

Open
@KasperZutterman

Description

@KasperZutterman

Context

At our company, we configure the required-version to a specific allowed version in pyproject.toml like this:

[tool.ruff]
line-length = 150
required-version = "==0.9.3"

Issue

If you don't have ruff, or a different version installed, you get the following error notification:

Image

   0.005164375s ERROR ThreadId(04) ruff_server::session::index::ruff_settings: Failed to resolve settings for /Users/kasperzutterman/Desktop/ruff_issue/pyproject.toml: Required version `==0.9.3` does not match the running version `0.9.7`

The above is great behaviour, however the extension falls back to the ruff version packaged with the extension, and skips the configuration defined by pyproject.toml.

This results in unintended formatting changes, that don't align with the company ruff configuration defined in pyproject.toml

Example

Below a minimal reproducible example:

Setup

# test.py

# Below line is 112 characters long, exceeding the  88 characters used as ruff default, but less than the line-length = 150 from pyproject.toml
example_line_too_long = ("value_1", "value_2", "value_3", "value_4", "value_5", "value_6", "value_7", "value_8")

With correct ruff version installed

  1. uv venv --python=312
  2. source .venv/bin/activate
  3. uv pip install ruff==0.9.3
  4. in vscode: >Ruff: format document

Result: no change, expected behaviour

Without ruff installed (or incorrect version)

  1. in vscode: >Ruff: format document

Result: code reformatted, ignoring line-length = 150 defined by pyproject.toml

# Below line is 112 characters long, exceeding the  88 characters used as ruff default, but less than the line-length = 150 from pyproject.toml
example_line_too_long = (
    "value_1",
    "value_2",
    "value_3",
    "value_4",
    "value_5",
    "value_6",
    "value_7",
    "value_8",
)

Question

  1. Is this the intended behaviour?
  2. If Yes, is there any setting that can be used to prevent ruff from making any changes when no correct version is found?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions