cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Override ruff linter settings for notebook cells

rgooch_cfa
Visitor

How can I override the ruff linter settings for my notebooks?

I have various projects/git folders in my workspace, and oftentimes, they represent different teams and thus different sets of code formatting patterns. I would like to override the default ruff settings on a project-by-project basis using `pyproject.toml` files in the project directories, similar to how I can do this locally. However, when these files are added, the ruff linter still ignores my specific settings.

I have tried my own ideas + looked for documentation but I can't find the info. Thanks for your help!

2 REPLIES 2

BigRoux
Databricks Employee
Databricks Employee

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.

rgooch_cfa
Visitor

Thanks for following up. I was following this documentation and the custom settings weren't picked up in my Databricks notebooks in the project directory. I've placed the `pyproject.toml` in the project root, but the ruff tooltip still appears (see screenshot)

rgooch_cfa_0-1734469244415.png

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group