Skip to content

Commit

Permalink
python: collect files with '[tool.ruff' sections as candidates for Ru…
Browse files Browse the repository at this point in the history
…ff config files (pantsbuild#18413)

Closes pantsbuild#18411 

The Ruff configuration can be specified using the `[tool.ruff]` section,
but also using any other arbitrary section that Ruff supports, e.g.

```
[tool.ruff.per-file-ignores]
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]
```

For other tools such as `mypy` or `pyright`, we search for the sections
with an open end:


https://github.com/pantsbuild/pants/blob/5f3f251a378f780daac07e0e5409c9a132571a89/src/python/pants/backend/python/typecheck/mypy/subsystem.py#L205


https://github.com/pantsbuild/pants/blob/4d612a50bf5de1374acb9736b804c81f6d17d183/src/python/pants/backend/python/typecheck/pyright/subsystem.py#L58


We should also do the same for Ruff otherwise config files with only
extended sections (i.e. without the `[tool.ruff]` section) won't be
picked up.
  • Loading branch information
AlexTereshenkov authored Mar 5, 2023
1 parent 5dd3dac commit 457e545
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/lint/ruff/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
specified_option_name=f"[{self.options_scope}].config",
discovery=self.config_discovery,
check_existence=["ruff.toml", *(os.path.join(d, "ruff.toml") for d in ("", *dirs))],
check_content={"pyproject.toml": b"[tool.ruff]"},
check_content={"pyproject.toml": b"[tool.ruff"},
)


Expand Down

0 comments on commit 457e545

Please sign in to comment.