Nested Workspace Omits Sub Configs, Probably Because Of Extend-exclude

by ADMIN 71 views

Nested Workspace Omitting Sub Configs: A Potential Bug in Ruff Configuration

As a developer working on complex projects with submodules, it's essential to have a clear understanding of how configuration files interact with each other. In this article, we'll explore a potential bug in Ruff configuration, specifically when dealing with nested workspaces and sub-configs. We'll delve into the issue, provide a minimal reproducible example, and discuss possible solutions.

When working on a project with submodules, it's common to have different settings for each submodule. To avoid conflicts and ensure that the CI only cares about the main repository, we use the extend-exclude feature in Ruff configuration. However, when developing in submodules, we want to use the entire collection of repositories. This is where the issue arises.

Let's consider the following directory structure:

ex/
├── .ruff.toml
├── sub
│   ├── .ruff.toml
│   ├── test.py
│   └── foo
│       └── test.py
└── test.py

The test.py files contain a long line of code:

print("That's a pretty long long long long long long long long long long long long long long long long long long long long long long line")

The Ruff configuration files are as follows:

# ex/.ruff.toml
target-version = "py312"
line-length = 120

extend-exclude = [
    "sub",
]
# ex/sub/.ruff.toml
target-version = "py312"
line-length = 120

extend-exclude = [
    "foo",
]

When we run Ruff on the temp directory, we get the following output:

  • Formatting temp/sub/foo/test.py does nothing as expected
  • Formatting temp/test.py breaks the long line as expected
  • Formatting temp/sub/test.py does nothing instead of breaking the line

The extension output reveals the issue:

DEBUG main ruff_server::session::index::ruff_settings: Indexing settings for workspace: <$HOME>/ex
2025-05-14 10:05:51.825783382 DEBUG ThreadId(04) ruff_server::session::index::ruff_settings: Loaded settings from: `<$HOME>/ex/.ruff.toml` for `<$HOME>/ex`
2025-05-14 10:05:51.825915250 DEBUG ThreadId(04) ruff_server::session::index::ruff_settings: Ignored path via `extend-exclude`: <$HOME>/ex/sub
2025-05-14 10:05:51.826834994  INFO main ruff_server::session::index: Registering workspace: <$HOME>/ex
2025-05-14 10:05:51.826868981 DEBUG main ruff_server::session::index::ruff_settings: Indexing settings for workspace: <$HOME>/ex/sub
2025-05-14 10:05:51.827300462 DEBUG main ruff_server::session::index::ruff_settings: Loaded settings from: `<$HOME>/ex/.ruff.toml`
2025-05- 10:05:51.827922641 DEBUG ThreadId(16) ruff_server::session::index::ruff_settings: Ignored path via `extend-exclude`: <$HOME>/ex/sub
2025-05-14 10:05:51.830188073  INFO main ruff_server::session::index: Registering workspace: <$HOME>/ex/sub
2025-05-14 10:05:51.836248830  INFO ruff:main ruff_server::server: Configuration file watcher successfully registered

As we can see, the issue arises when Ruff tries to load the settings for the ex/sub workspace. Instead of loading the ex/sub/.ruff.toml file, it ignores the path via extend-exclude.

Based on the analysis, it seems that the issue is related to the way Ruff handles nested workspaces and sub-configs. One possible solution is to modify the getProjectRoot function to take into account the extend-exclude feature when loading settings for nested workspaces.

Another possible solution is to refactor the Ruff configuration system to better handle nested workspaces and sub-configs. This might involve introducing new features or modifying existing ones to ensure that Ruff can correctly load and apply settings for nested workspaces.

In conclusion, the issue of nested workspaces omitting sub-configs is a potential bug in Ruff configuration. By analyzing the minimal reproducible example and the extension output, we can see that the issue arises when Ruff tries to load settings for the ex/sub workspace. Possible solutions include modifying the getProjectRoot function or refactoring the Ruff configuration system to better handle nested workspaces and sub-configs.

If you're experiencing similar issues with Ruff configuration, we recommend trying the following:

  1. Check your Ruff configuration files to ensure that they are correctly set up and that the extend-exclude feature is not causing any conflicts.
  2. Try modifying the getProjectRoot function to take into account the extend-exclude feature when loading settings for nested workspaces.
  3. Consider refactoring the Ruff configuration system to better handle nested workspaces and sub-configs.

By following these recommendations, you should be able to resolve the issue and ensure that Ruff correctly loads and applies settings for your nested workspaces.
Nested Workspace Omitting Sub Configs: A Potential Bug in Ruff Configuration

Q&A: Understanding the Issue and Possible Solutions

Q: What is the issue with nested workspaces omitting sub-configs in Ruff configuration?

A: The issue arises when Ruff tries to load settings for a nested workspace, but it ignores the sub-configs due to the extend-exclude feature. This can lead to incorrect formatting and other issues.

Q: What is the extend-exclude feature in Ruff configuration?

A: The extend-exclude feature allows you to exclude certain directories or files from being formatted by Ruff. This can be useful for ignoring certain files or directories that are not relevant to the project.

Q: How does the getProjectRoot function affect the issue?

A: The getProjectRoot function is responsible for determining the root directory of the project. However, it seems to be ignoring the sub-configs due to the extend-exclude feature. Modifying this function to take into account the sub-configs may resolve the issue.

Q: What are the possible solutions to this issue?

A: There are two possible solutions:

  1. Modify the getProjectRoot function to take into account the sub-configs.
  2. Refactor the Ruff configuration system to better handle nested workspaces and sub-configs.

Q: How can I troubleshoot this issue?

A: To troubleshoot this issue, you can try the following:

  1. Check your Ruff configuration files to ensure that they are correctly set up and that the extend-exclude feature is not causing any conflicts.
  2. Try modifying the getProjectRoot function to take into account the sub-configs.
  3. Consider refactoring the Ruff configuration system to better handle nested workspaces and sub-configs.

Q: What are the benefits of resolving this issue?

A: Resolving this issue will ensure that Ruff correctly loads and applies settings for your nested workspaces. This will prevent incorrect formatting and other issues that can arise from the extend-exclude feature.

Q: How can I contribute to resolving this issue?

A: If you're experiencing similar issues with Ruff configuration, you can contribute to resolving this issue by:

  1. Reporting the issue on the Ruff GitHub repository.
  2. Providing a minimal reproducible example to help the developers understand the issue.
  3. Offering suggestions or solutions to the issue.

Q: What is the current status of this issue?

A: The issue is currently being investigated by the Ruff developers. However, no official fix has been released yet. We recommend keeping an eye on the Ruff GitHub repository for updates on this issue.

In conclusion, the issue of nested workspaces omitting sub-configs is a potential bug in Ruff configuration. By understanding the issue and possible solutions, you can troubleshoot and resolve this issue. We recommend keeping an eye on the Ruff GitHub repository for updates on this issue and contributing to resolving it if you're experiencing similar issues.