astral-sh / astral-sh/ruff-vscode

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

Open
#548 2 comments 0 reactions 0 assignees View on GitHub
multi-root-workspaces needs-mre
Dominant language
TypeScript
Stars
1.7k
Forks
80
Avg merge
8h 22m
Merged PRs (30d)
22

Description

## 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:

```python
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:

```python
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:

```python
from typing import TypeAlias

import pandas as pd

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

## Additional Context
- This issue does not occur in single-root workspaces; the extension correctly uses the environment's Ruff version that matches the `required-version` specified in `pyproject.toml` (the one from the venv).
- Setting the `required-version` to the bundled version (`0.5.3`) allows the extension to read the `pyproject.toml` configurations, but this is not a viable workaround for projects requiring a different Ruff version.

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?

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with a multi-root workspace, separate pyproject.toml files, project Ruff version 0.5.4, bundled version 0.5.3, and ruff.importStrategy set to fromEnvironment. Trace the extension's workspace-root and Ruff-version selection behavior. Done means each root honors its required-version and applies its project configuration, while single-root behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.