Steps to Ensure Ruff Reads `pyproject.toml`
1. Place `pyproject.toml` in the Project Root:
- Ruff automatically detects configuration files like `pyproject.toml`, `ruff.toml`, or `.ruff.toml` when they are located at the root of the project directory. Ensure your `pyproject.toml` is in the correct directory for each project.
2. Define Ruff Settings in `pyproject.toml`:
- Use the `[tool.ruff]` section to define your desired settings. For example:
```toml
[tool.ruff]
line-length = 120
select = ["E", "F", "W"]
ignore = ["E501"]
```
- This ensures Ruff uses these specific rules and ignores others.
3. Verify Configuration Detection:
- Run Ruff manually using the command:
```bash
ruff check . --config pyproject.toml
```
- This explicitly tells Ruff to use your configuration file. If you see a message like `Using pyproject.toml at /path/to/project`, it confirms that Ruff is reading the file.
4. Handle Workspace or Global Overrides:
- In environments like Databricks or VSCode, global or workspace-level configurations may override project-specific settings. For instance:
- In VSCode, check if `ruff.format.args` or similar settings are overriding your `pyproject.toml`. You can unset these or explicitly specify the path to your configuration file.
- In Databricks, ensure no global Ruff configurations are conflicting.
5. Pass Configuration Explicitly (if Necessary):
- If automatic detection fails, you can pass the configuration file explicitly in commands or pre-commit hooks:
```bash
ruff check . --config=/path/to/pyproject.toml
```
- For pre-commit hooks, update the arguments to include:
```yaml
args: ["--config=pyproject.toml"]
``'
6. Check for Nested Configurations:
- If you have multiple configuration files (e.g., one at a parent directory and another at a subdirectory), Ruff might prioritize one over the other. Ensure only the intended file exists for each project.