python.languageServer setting: JediCalling "Python refactor: Sort imports" from command palette sorts import in active document
Nothing happens
Devtools console:
Error: /home/me/work/proj/venv/lib/python3.8/site-packages/setuptools/distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
warnings.warn(
at i (/home/me/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:1)
at Socket.<anonymous> (/home/me/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:1)
at Socket.emit (events.js:203)
at addChunk (_stream_readable.js:295)
at readableAddChunk (_stream_readable.js:276)
at Socket.Readable.push (_stream_readable.js:210)
at Pipe.onStreamRead (internal/stream_base_commons.js:166)
$onExtensionRuntimeError @ workbench.desktop.main.js:sourcemap:4312
Output pane:
> ~/work/proj/venv/bin/python ~/.vscode/extensions/ms-python.python-2020.6.91350/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.6.91350/pythonFiles/sortImports.py - --diff
cwd: ~/work/proj
This warning comes from isort that is installed in venv, both versions 4.3.21 and 5.0.9 (latest) produce this warning. Downgrading setuptools to <49.2 makes "Sort imports" command to work ok again - and this warning disappears. I believe this should not behave this way since even with the warning isort exit code is 0.
The issue with isort has been fixed in 5.1.0 but I believe the extension ships with some older version. Setting isort path to installed in workspace venv produces this traceback in dev console:
Error: Traceback (most recent call last):
File "venv/bin/isort", line 8, in <module>
sys.exit(main())
File "/home/me/work/proj/venv/lib/python3.8/site-packages/isort/main.py", line 693, in main
at i (/home/me/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:1)
at Socket.<anonymous> (/home/me/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:1)
at Socket.emit (events.js:203)
at addChunk (_stream_readable.js:295)
at readableAddChunk (_stream_readable.js:276)
at Socket.Readable.push (_stream_readable.js:210)
at Pipe.onStreamRead (internal/stream_base_commons.js:166)
$onExtensionRuntimeError @ mainThreadExtensionService.ts:66
_doInvokeHandler @ rpcProtocol.ts:402
_invokeHandler @ rpcProtocol.ts:387
_receiveRequest @ rpcProtocol.ts:303
_receiveOneMessage @ rpcProtocol.ts:230
(anonymous) @ rpcProtocol.ts:105
fire @ event.ts:587
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:587
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:203
addChunk @ _stream_readable.js:295
readableAddChunk @ _stream_readable.js:276
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
Running isort filename.py --diff in terminal works fine. Unfortunately the Python traceback is cut off before anything interesting is printed.
Maybe run isort with PYTHONWARNINGS="ignore"? As it stands this will reappear any time a warning is output by isort or any of its dependencies.
Things did not change with isort 5.1.1 - isort itself runs fine without issues (both with file name and stdin), fails when called from extension. The only way to have this command working is to downgrade setuptools.
I ran into this problem.
I was able to โfixโ it by editing pythonFiles/sortImports.py
sys.stdin = io.BytesIO(stdin.read())
# End workaround
import setuptools # <โ insert this line
import isort.main
isort.main.main()
None of workaround specified so far has worked for me. i.e, downgrading setuptools to <49.2 or adding import statement in sortImports.py file.
@zgoda
The issue with isort has been fixed in 5.1.0 but I believe the extension ships with some older version.
True, isort >5.1.0 fix it.
The issue is if someone use Pylint. Pylint is not yet compatible wiht isort 5 and thus lists in its dependencies isort <5.
That's why we are stuck at isort 4.3.21 .
https://github.com/PyCQA/pylint/issues/3722
@OutOfFocus4
I first tried your solution, to edit pythonFiles/sortImports.py but sadly it did not work out for me...
Then I check and the reason why is becuse I am using my env's isort "python.sortImports.path": "C:\\Users\\PC-Gil\\Miniconda3\\envs\\forge\\Scripts\\isort.exe" . So I am not reaching the sortImports.py script. I prefer to use my env's isort so I can control the version I use.
@zgoda @jahan01
I downgraded setuptools to 49.1.3, which remove the error from isort 4.3.21.
Now, I am having a weird behavior:
When "python.sortImports.args" is set (I tried a combination of one or more arguments from this list :
[ "--multi-line=3", "--trailing-comma", "--force-grid-wrap=0", "--use-parentheses", "--line-length=119", ] ),
then the sort import is broken (doesn't work, and if set in "editor.codeActionsOnSave", prevents saving with infinite message Saving 'filename.py': Applying code action 'Sort imports'.). And it is broken with both isort, from vscode and from my env.
Here the Output pane when I sort with one args set for isort:
-With vscode's isort
> ~\Miniconda3\envs\forge\python.exe c:\Users\PC-Gil\.vscode\extensions\ms-python.python-2020.7.94776\pythonFiles\pyvsc-run-isolated.py c:\Users\PC-Gil\.vscode\extensions\ms-python.python-2020.7.94776\pythonFiles\sortImports.py - --diff --line-length=119
cwd: c:\Users\PC-Gil\Documents\test
```
-With my env's isort
~\Miniconda3\envs\forge\Scriptsisort.exe - --diff --line-length=119
cwd: c:\Users\PC-Gil\Documents\test
```
If "python.sortImports.args" is not set, then it work perfectly, (with vscode's isort as well as with my env's isort) but with the default isort's settings....
I read in another issue that we can set isort args in a config file (https://github.com/microsoft/vscode-python/issues/5840#issuecomment-497321419).
I tried "python.sortImports.args": ["--settings-path=${workspaceFolder}\\setup.cfg"] and for now it works for me.
@zgoda I am able to reproduce this issue with the version you specified, thanks. However with the latest version, I no longer see this issue, please upgrade to the latest extension and let me know.
Can you please try setting PYTHONWARNINGS="ignore" in environment file and see if you still see this warning?
I believe this should not behave this way since even with the warning isort exit code is 0.
That's apparently not true. Quoting the docs: _"If any warning is found, the command will exit with an error code"_
Extension version v2020.7.94776
Vendored isort still throws an exception and does not work if setuptools 49.2 is installed in PYTHONPATH.
Custom provided isort 5.1.4 works fine.
Extension version v2020.7.94776
Vendored isort still throws an exception and does not work if setuptools 49.2 is installed in PYTHONPATH.
Custom provided isort 5.1.4 works fine.
can confirm. downgraded setuptools to 49.1 and it works again
For some reason, I am unable to repro the issue reliably - but I do see it. Seems to me that we can either go with @OutOfFocus4 's approach or pinning setuptools, as Pylint is not yet compatible with isort 5.
We're going to upgrade isort and make sure it doesn't break pylint.
Pylint is installed within the user environment itself, which will have it's own copy of isort. My guess is we pick that isort instead of the one shipped with the extension when using the pylint command, in my case:
~\AppData\Local\Programs\Python\Python37\python.exe c:\Users\karraj\.vscode-insiders\extensions\ms-python.python-2020.6.91350\pythonFiles\pyvsc-run-isolated.py pylint --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text c:\Users\karraj\Desktop\imports\a.py
but this is something to double check as well.
Some concerns with upgrading isort: https://github.com/microsoft/vscode-python/issues/12932#issuecomment-667233403
Downloading isort-5.3.2-py3-none-any.whl (93 kB)
|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 93 kB 166 kB/s
ERROR: pylint 2.5.3 has requirement isort<5,>=4.2.5, but you'll have isort 5.3.2 which is incompatible.
Import, install , isort many commands do not work. Anaconda3 prompt does not recognize all those commands and I can not open Jupyter notebook and others, Recently I installed conda3, my previous version was working fine which I delete because some files was missing. I tried lots of command did not work. Anaconda Doc I Read all, no solution I have seen.
Please any advice for fix
Upgraded isort. Should be fixed in the next release
Mr. RajNothing workI may be send some clue not sure
-----Original Message-----
From: Kartik Raj notifications@github.com
To: microsoft/vscode-python vscode-python@noreply.github.com
Cc: uksaha sahauttamkumar@aol.com; Comment comment@noreply.github.com
Sent: Thu, Aug 13, 2020 1:42 pm
Subject: Re: [microsoft/vscode-python] Python refactor: Sort imports does not work with setuptools 49.2 (#12949)
Closed #12949.โ
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
It'll be fixed in the NEXT RELEASE which is scheduled in a month.
Mr. RajHow far you are now, everything mess, waiting long,almost every week I tried same asPlease let me know
Uttam
-----Original Message-----
From: Kartik Raj notifications@github.com
To: microsoft/vscode-python vscode-python@noreply.github.com
Cc: uksaha sahauttamkumar@aol.com; Comment comment@noreply.github.com
Sent: Sat, Aug 15, 2020 4:10 am
Subject: Re: [microsoft/vscode-python] Python refactor: Sort imports does not work with setuptools 49.2 (#12949)
It'll be fixed in the NEXT RELEASE which is scheduled in a month.โ
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
Fix is already out on insiders. Try the Switch to insiders weekly channel command, which installs the insiders version of the extension.
Removing python.sortImports.path from settings.json fixed the issue for me
Most helpful comment
I ran into this problem.
I was able to โfixโ it by editing
pythonFiles/sortImports.py