astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.04k stars 52 forks source link

Ruff Extension ignores "required-version" in pyproject.toml for multi-root workspaces #548

Open CodeTex opened 1 month ago

CodeTex commented 1 month ago

Description

When operating in a multi-root workspace with the ruff-vscode extension installed, the extension does not adhere to the required-version configuration specified in pyproject.toml for selecting the Ruff version. Despite configuring a specific Ruff version (e.g., 0.5.4) that differs from the bundled version (0.5.3) with the extension, and setting ruff.importStrategy to "fromEnvironment", the extension defaults to using the bundled Ruff executable. This behavior prevents the application of project-specific Ruff configurations defined in pyproject.toml.

Steps to Reproduce

  1. Install ruff-vscode extension version 2024.34.0, which comes bundled with Ruff v0.5.3.
  2. In a multi-root workspace, configure a project with pyproject.toml to require Ruff version 0.5.4 (available in the project's virtual environment).
  3. Set ruff.importStrategy to "fromEnvironment" in the workspace settings.
  4. Run with I rule set, with lines-after-imports set to 2, on a sample file like:
from typing import TypeAlias
import pandas as pd
df = pd.DataFrame()
x = TypeAlias('x', pd.DataFrame)

Expected Behavior

The extension should respect the required-version configuration in pyproject.toml and use the Ruff version from the environment that matches this requirement, allowing for project-specific configurations to be applied. Resulting in the sample file to:

from typing import TypeAlias

import pandas as pd

df = pd.DataFrame()
x = TypeAlias('x', pd.DataFrame)

Actual Behavior

The extension defaults to using the bundled Ruff version (0.5.3), disregarding the required-version configuration in pyproject.toml and the ruff.importStrategy setting. Resulting in sample file:

from typing import TypeAlias

import pandas as pd

df = pd.DataFrame()
x = TypeAlias('x', pd.DataFrame)

Additional Context

Is there maybe another way to have the extension pick the ruff version as defined in every root's pyproject.toml or am I shooting for something not intended here?

dhruvmanila commented 1 month ago

Hey, thanks for the detailed report.

What I understand here is that you want to configure the extension to use a specific Ruff version. This cannot be configured via the config files because the VS Code extension is completely independent to the ruff executable. What I mean is that the extension does not read any config files as it is Ruff's responsibility to do so.

Now, before I proceed can you verify your use-case? Is it only to update the lines-after-imports value for different folder in your workspace or is it to use different Ruff version for the folders in your workspace or both?