New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting order is broken and not following standard sort order #2239
Comments
Hi Chase, Thank you for the message! |
Hi @bp72. I am facing the same issue in ClickHouse/ClickHouse#60444 You can quickly clone the ClickHouse/ClickHouse repository and jump across the |
Here's how to reproduce the issue:
|
It looks like the issue is the default config.src_paths
So, here's the question. Is there a way to define all known first-party directories in the repository? update: pylint actually understands, that this is a first-party library:
|
The issue can't be solved in nice and easy way. module_with_reason is not aware of the file path. I think I can try to change its signature (and all others) to accept an optional src_path based on the file name or the current directory, if the input is stdin, and pass it to file_contents and all down the road. WDYT? |
Dear @bp72 and @staticdev, I'd like to include I want to fix it myself, but it's helpful to discuss how to do it correctly in advance. |
Hi @Felixoid , Can't you just add your tests to In your [tool.isort]
profile = "black"
src_paths = ["src", "tests/ci"] Continuing your example ⬆️ and configuring using ❯ git -P diff
diff --git a/pyproject.toml b/pyproject.toml
index 3d05abd9e..68d22f973 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -38,3 +38,6 @@ disable = '''
# due to SQL
min-similarity-lines=1000
+[tool.isort]
+profile = "black"
+src_paths = ["src", "tests/ci"]
diff --git a/tests/ci/pr_info.py b/tests/ci/pr_info.py
index c61e62f33..2cb83a22d 100644
--- a/tests/ci/pr_info.py
+++ b/tests/ci/pr_info.py
@@ -6,12 +6,9 @@ import re
from typing import Dict, List, Set, Union
from urllib.parse import quote
-# isort: off
# for some reason this line moves to the end
from unidiff import PatchSet # type: ignore
-# isort: on
-
from build_download_helper import get_gh_api
from env_helper import (
GITHUB_EVENT_PATH, ❯ isort -v tests/ci/pr_info.py
_ _
(_) ___ ___ _ __| |_
| |/ _/ / _ \/ '__ _/
| |\__ \/\_\/| | | |_
|_|\___/\___/\_/ \_/
isort your imports, so you don't have to.
VERSION 5.13.2
else-type place_module for json returned STDLIB
else-type place_module for logging returned STDLIB
else-type place_module for os returned STDLIB
else-type place_module for re returned STDLIB
from-type place_module for typing returned STDLIB
from-type place_module for urllib.parse returned STDLIB
from-type place_module for unidiff returned THIRDPARTY
from-type place_module for build_download_helper returned FIRSTPARTY
from-type place_module for env_helper returned FIRSTPARTY ❯ git -P diff tests/ci/pr_info.py
diff --git a/tests/ci/pr_info.py b/tests/ci/pr_info.py
index c61e62f33..2cb83a22d 100644
--- a/tests/ci/pr_info.py
+++ b/tests/ci/pr_info.py
@@ -6,12 +6,9 @@ import re
from typing import Dict, List, Set, Union
from urllib.parse import quote
-# isort: off
# for some reason this line moves to the end
from unidiff import PatchSet # type: ignore
-# isort: on
-
from build_download_helper import get_gh_api
from env_helper import (
GITHUB_EVENT_PATH,
|
@sztamas interesting. I didn't know it worked as well when the > git diff
diff --git a/pyproject.toml b/pyproject.toml
index 3d05abd9ec2..ab21d3064cb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -7,6 +7,10 @@ max-branches=50
max-nested-blocks=10
max-statements=200
+[tool.isort]
+profile = "black"
+src_paths = ["src", "tests/ci"]
+
[tool.pylint.FORMAT]
#ignore-long-lines = (# )?<?https?://\S+>?$
diff --git a/tests/ci/pr_info.py b/tests/ci/pr_info.py
index c61e62f334c..f134487c0a2 100644
--- a/tests/ci/pr_info.py
+++ b/tests/ci/pr_info.py
@@ -6,12 +6,8 @@ import re
from typing import Dict, List, Set, Union
from urllib.parse import quote
-# isort: off
-# for some reason this line moves to the end
from unidiff import PatchSet # type: ignore
-# isort: on
-
from build_download_helper import get_gh_api
from env_helper import (
GITHUB_EVENT_PATH,
I assume it's enough to add any problematic path to the pyproject? It looks relatively easy fix for our case. |
Yes, you should add all directories where your project stores source files to I hope this helps! |
It does indeed, thank you! Would you consider improvements/brainstorming on how to identify it automatically? |
No worries, I'm glad it helped! To be honest, I wasn't active on this project for quite a while, so it would quite an effort and I'm not sure if I'll have the bandwidth for it. |
hmmmmmm... I see. The issue clarifies the context very well. Maybe the project settings work better than magic. |
Hi @inboxcda I know that it's been a while, but , as the OP, if you could have any other example when Based on the problems you are seeing, it might be the same issue above. ie. Thanks, |
I love the idea of isort! Genius! However, I know the recommended way to sort in Python is something like this:
On Top: standard libraries
Middle: third party libraries
Bottom: packages/files defined locally (in the tree where this files resides)
This doesn't seem to be the case with isort and I cannot find hardly anything online about it. Sometimes the lines are not even sorted alphabetically, and also it doesn't seem to differentiate between pip packages and local packages as my pip packages are at the bottom most times. I have tried testing this on several files and projects on different computers with different VScode configurations and even clean vscode installs, and I don't really see the pattern working to the Python standard. It is possible to configure isort so that it does sort to the python standard?
I have tried with the autopep8 and black formatters. With the recommended json settings config. The sort happens, but it is sorting incorrectly to my understanding.
Thanks in advance for the help! I am really hoping to get this sort working properly or to be educated by someone if I am completely missing something.
Cheers,
Chase
The text was updated successfully, but these errors were encountered: