-
Notifications
You must be signed in to change notification settings - Fork 23
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
isort
does not pick up settings if they are not in the workspace folder
#53
Comments
@den-is The built in Can you also try adding this?
|
@karthiknadig regarding including
ok... let's fix it and add isort.cfg there. [settings]
profile=black
line_length=99
skip_gitignore=true Adding that setting still made to move my LOCALFILE and put it with THIRDPARTY adding: these are all vscode settings related to python that I have: "python.languageServer": "Pylance",
"python.formatting.provider": "black",
"python.linting.pylintArgs": [
"--disable=missing-docstring,unused-import",
"--max-line-length=99"
],
"python.linting.flake8Args": [
"--max-line-length=99",
"--ignore=E402,F841,F401"
],
"python.linting.pylintPath": "/home/vscode/.local/bin/pylint",
"[python]": {
"editor.tabSize": 4,
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"black-formatter.args" : [
"--line-length",
"99"
],
// "isort.path": ["/usr/local/bin/isort"],
"isort.args": [
"--profile",
"black",
"--line-length",
"99",
"--skip-gitignore",
"--settings-file",
"./.isort.cfg",
], my complete .devcontainer settings, feel free to use it: {
"name": "py3",
"image": "diskandarov/pydevenv",
// "forwardPorts": [5000],
"settings": {
"editor.tabSize": 2,
"terminal.integrated.defaultProfile.linux": "zsh",
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
// required if not using "ms-python.black-formatter" ext
"python.formatting.blackArgs": ["--line-length", "99"],
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.sortImports.path": "/usr/local/py-utils/bin/isort",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.languageServer": "Pylance",
"[python]": {
"editor.tabSize": 4,
// requires "ms-python.black-formatter"
// not able to install not-released "dev" extension into devcontainer
// "editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"black-formatter.args" : [
"--line-length",
"99"
],
"isort.args":[
"--profile",
"black",
"--skip-gitignore",
"--line-length",
"99"
],
// specific linters settings should go in own config files in project's root
"python.linting.pylintArgs": [
"--max-line-length=99",
"--disable=C0111,W0611"
],
"python.linting.flake8Args": [
"--max-line-length=99",
"--ignore=E402,F841,F401,W503"
]
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
// not working, can't install unreleased dev extensions
// "ms-python.black-formatter",
// "ms-python.isort",
"formulahendry.code-runner",
"mrmlnc.vscode-duplicate",
"redhat.vscode-yaml",
"ahebrank.yaml2json",
"mechatroner.rainbow-csv",
"oderwat.indent-rainbow",
"semgrep.semgrep",
"esbenp.prettier-vscode"
],
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
// Install globaly probably as root user.
// "postCreateCommand": "pip install -r requirements.txt",
// Install with user that runs container non-root.
// Helps to avoid breaking dependencies and interfering with system libs.
"postCreateCommand": ".devcontainer/startup.sh",
} |
Would it be possible for you to provide a minimal repro of this, if you can't share the entire project? Note that there is a limitation in VS Code on installing pre-release versions of extension in dev container. See here on how to add them: |
I ran into the same issue. I have black and isort extensions running in VSCode. Works like a charm. I also implemented a git pre-commit hook that runs black and isort. This can be used by teammates not using VSCode. One would expect the outcome to be the same. But the extension isort removes a new line in my imports and running it from command line adds one. I use the default settings for both. |
I have really tried to come up with some trivial python package with a couple of modules in it and external dependencies. But it somehow did not work for a trivial package. I have even tried to set a custom I have removed that new isort extension and everything started to work as intended. |
This might be something that I will need input from In vscode-python extension, we insert the path to isort bundled with the python extension and then call main on it.
in vscode-python extension we get the diff and try to calculate the edits. The content of the file is passed in via stdin.
Where as in vscode-isort, we insert the path to isort bundled with the python extension and then call
in vscode-isort extension we get the formatted content and use it directly. The content of the file is passed in via stdin.
So not really sure why there is any difference here. |
Created PyCQA/isort#1940 on |
Ran into the same issue. Had to disable extension for everything to work as intended |
@SandroJijavadze Can you try adding Run that same thing |
I just reenabled isort to test your suggestion bu I can't seem to get it working at all anymore. Restarted vscode, cleared settings.json, etc but still, I get shis error:
|
@SandroJijavadze Can you try switching to the pre-release version? Do you see anything else in the Output > isort panel? |
Switched to pre-release, repeated steps (restart, test with/without options, etc) still get the same output:
In isort panel:
If I comment out settings.json then I get additional:
If I run
|
@SandroJijavadze I see two other issues that I need to address before we can get to digging into the original problem here.
I will post next steps on those issues. We will come back to this once we have that. It should make it easier to dig into the difference between bundled isort and isort in terminal. |
After investigation it looks like this comes from |
isort
does not pick up settings if they are not in the workspace folder
FYI I've also just raised microsoft/vscode-python#20205 because this actually used to work for us before updating to VScode 1.73.1. Perhaps the minimal reproduction example I've created there may be of any help? |
@bluenote10 the problem is with how Python extension used to work around this by creating a temporary file and saving the content there, and then running isort on it. The issue with that approach was that as VS Code started to light up newer ways to work with repositories, we can't continue to support that workaround for Here is a work around, add this to your setting: You could actually turn this into a multi root project, with your main directory, and your sub-directory as two roots. Like this:
That will allow |
Another workaround for this using the tasks and keybinding: |
Yeah, I'm wondering if providing a task as a fallback option makes sense? Otherwise we could have the language server fallback to subprocess if the config file is found somewhere else (although honestly I think it would be better if folks specified the config location instead). |
Since PyCQA/isort#1992 is fixed now. Am I understanding it correctly that this should be also be resolved? I installed latest isort, pre-release version of ms-python.isort. But still no luck, still experiencing this issue. |
@Olindholm Please see the |
I always put the The only way I could make |
Same problem here, I also tried to debug with the -v option passed as args in the settings, but the output is written to the file sorted instead of being written to the log. |
@matteoaletti As for getting config info. you can set the log level for the isort extension to If people are looking for alternatives, look for Ruff extension. It is a multi-tool of python tools, it has import sorting, formatting support, and implements several linte rules (like pylint, flake8, pycodestyle, pydocstyle, bandit, pyflakes etc). It is implemented in rust and is blazingly fast. It is built on top of our templates for contributing python tools extensions for VS Code. |
@karthiknadig thank you for your answer, I had indeed tried the "develop" version of isort and it works! |
This appears to have been fixed as of isort Updating the bundled isort to the latest isort should clear this up (as of this comment that is version Until that is done you should be able to work with a local (virtualenv installation) by installing said versions into your environment and using the "fromEnvironment" import strategy in the vscode/isort settings. json for that setting is {
"isort.importStrategy": "fromEnvironment"
} |
Found updates this thread in my email. Decided to share my workflow. Ruff formatting - formats imports only, also configured to use |
I have two VSCode dev environments:
One is my local workstation VScode (mac) with the latest isort and black available in $PATH.
The other one is pure devcontainer with controlled environment and the latest isort and black available as well.
Before the latest vscode isort and black extensions. I was able to pick the correct configuration using isort.cfg in the root of each project.
That way both VScode environments where not fighting with each other and were not applying different "standards".
With the installation of "ms-python.isort" the situation has changed:
Local vscode is using new "built-in" isort.
While I by default was not able to install dev-extenstion in dev-container - container continued using standard isort.
this is the only isort config included in both vscode settings and isort.cfg
Now ms-python.isort is trying to apply this standard:
while native isort is trying to apply:
MS extension is putting local module with the third-party module in one section and alphabetically above it.
Your ms-python.isort built-in isort is using "wrong", non-default sections setting. Thas is documented here:
https://pycqa.github.io/isort/docs/configuration/custom_sections_and_ordering.html
I need this:
sections=FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,LOCALFOLDER
Providing
"isort.path": ["/usr/local/bin/isort"]
setting has completely broken Formatting. Will open separate issue.The text was updated successfully, but these errors were encountered: