-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
isortRelated to import sortingRelated to import sorting
Description
Hi, team. Thanks for your hard work.
I noticed a change in how known-first-party imports get classified recently.
If I'm working on my_namespace.a project, I expect my_namespace.b to be classified as a Known(ThirdParty) (so does isort). This was the case with ruff as well, up until version 0.5.7 .
Working on my_namespace.a project, with the following stucture:
ruff-namespace-src-imports-test/
├─ main.py
├─ ruff.toml
└─ src/
└─ my_namespace/
└─ a/
└─ ...
# ruff.toml
[lint.isort]
known-first-party = ["my_namespace.a"]# main.py
import os
import my_namespace.b
import numpy
import my_namespace.a^ I see it as a valid import order, so does v0.5.6:
$ python3.12 -m ruff check main.py --select I --diff -v
[2024-08-19][11:11:40][ruff::resolve][DEBUG] Using configuration file (via parent) at: C:\ruff-namespace-src-imports-test\ruff.toml
[2024-08-19][11:11:40][ruff_workspace::pyproject][DEBUG] `project.requires_python` in `pyproject.toml` will not be used to set `target_version` when using `ruff.toml`.
[2024-08-19][11:11:40][ruff::commands::check][DEBUG] Identified files to lint in: 4.5661ms
[2024-08-19][11:11:40][ruff::diagnostics][DEBUG] Checking: C:\ruff-namespace-src-imports-test\main.py
[2024-08-19][11:11:40][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'my_namespace.a' as Known(FirstParty) (KnownFirstParty)
[2024-08-19][11:11:40][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'os' as Known(StandardLibrary) (KnownStandardLibrary)
[2024-08-19][11:11:40][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'my_namespace.b' as Known(ThirdParty) (NoMatch)
[2024-08-19][11:11:40][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'numpy' as Known(ThirdParty) (NoMatch)
[2024-08-19][11:11:40][ruff::commands::check][DEBUG] Checked 1 files in: 2.7995ms
But 0.5.7+ (including the latest 0.6.1) sees otherwise:
$ python3.12 -m ruff check main.py --select I --diff -v
[2024-08-19][11:12:44][ruff::resolve][DEBUG] Using configuration file (via parent) at: C:\ruff-namespace-src-imports-test\ruff.toml
[2024-08-19][11:12:44][ruff_workspace::pyproject][DEBUG] `project.requires_python` in `pyproject.toml` will not be used to set `target_version` when using `ruff.toml`.
[2024-08-19][11:12:44][ruff::commands::check][DEBUG] Identified files to lint in: 4.8756ms
[2024-08-19][11:12:44][ruff::diagnostics][DEBUG] Checking: C:\ruff-namespace-src-imports-test\main.py
[2024-08-19][11:12:44][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'my_namespace.a' as Known(FirstParty) (KnownFirstParty)
[2024-08-19][11:12:44][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'os' as Known(StandardLibrary) (KnownStandardLibrary)
[2024-08-19][11:12:44][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'my_namespace.b' as Known(FirstParty) (SourceMatch("C:\\ruff-namespace-src-imports-test\\src"))
[2024-08-19][11:12:44][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'numpy' as Known(ThirdParty) (NoMatch)
[2024-08-19][11:12:44][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'my_namespace.b' as Known(FirstParty) (SourceMatch("C:\\ruff-namespace-src-imports-test\\src"))
[2024-08-19][11:12:44][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'os' as Known(StandardLibrary) (KnownStandardLibrary)
[2024-08-19][11:12:44][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'numpy' as Known(ThirdParty) (NoMatch)
[2024-08-19][11:12:44][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'my_namespace.a' as Known(FirstParty) (KnownFirstParty)
--- main.py
+++ main.py
@@ -1,6 +1,6 @@
import os
-import my_namespace.b
import numpy
import my_namespace.a
+import my_namespace.b
[2024-08-19][11:12:44][ruff::commands::check][DEBUG] Checked 1 files in: 2.8168ms
Would fix 1 error.
Removing src/my_namespace correctly classifies my_namespace.b as known-third-party again.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
isortRelated to import sortingRelated to import sorting