Confusion with src and running in different directories #15538
-
When I run Ruff with the isort rule from different directories, I get different results. I could use some help if I am misunderstanding or have misconfigured something. Minimal reproducible example: https://github.com/joecox/ruff-rel-example. In a nutshell, with the structure:
With pyproject.toml:
And
Running Ruff from
But running Ruff from the root folder does not recognize the first-party import as such: $ uvx --from "ruff==0.9.2" ruff check --diff --config=backend/pyproject.toml .
--- backend/a.py
+++ backend/a.py
@@ -1,3 +1,2 @@
-from requests import get
-
from b import foo
+from requests import get
Would fix 1 error. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thank you for taking the time to create a minimal reproducible example repository, that helps in understanding the issue quickly. The reason this is happening is because of the $ ruff check --no-cache --diff --config=backend/pyproject.toml -v .
[2025-01-17][10:43:33][ruff::resolve][DEBUG] Using user-specified configuration file at: backend/pyproject.toml
...
[2025-01-17][10:43:33][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'requests' as Known(ThirdParty) (NoMatch)
[2025-01-17][10:43:33][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'b' as Known(ThirdParty) (NoMatch)
[2025-01-17][10:43:33][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'b' as Known(ThirdParty) (NoMatch)
[2025-01-17][10:43:33][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'requests' as Known(ThirdParty) (NoMatch) And, when you run $ ruff check --no-cache --diff -v .
[2025-01-17][10:45:52][ruff::resolve][DEBUG] Using configuration file (via parent) at: /private/tmp/ruff-rel-example/backend/pyproject.toml
...
[2025-01-17][10:45:52][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'requests' as Known(ThirdParty) (NoMatch)
[2025-01-17][10:45:52][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'b' as Known(FirstParty) (SourceMatch("/private/tmp/ruff-rel-example/backend")) Related: #10989 (specifically, from #10989 (comment)) Can you provide more details about your intended workflow? Why do you need to use the |
Beta Was this translation helpful? Give feedback.
Thank you for taking the time to create a minimal reproducible example repository, that helps in understanding the issue quickly.
The reason this is happening is because of the
--config
option which if provided will try to resolve the path using the current working directory and make the current working directory as the project root. This means that bothb
andrequests
are considered as third party as seen using the--verbose
flag: