Skip to content
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

"Organize Imports" does nothing #13948

Closed
Lexicality opened this issue Sep 16, 2020 · 13 comments
Closed

"Organize Imports" does nothing #13948

Lexicality opened this issue Sep 16, 2020 · 13 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@Lexicality
Copy link

Environment data

  • Language Server version: 2020.9.4
  • OS and version: WSL2/Ubuntu 20.04.1 LTS
  • Python version: 3.6.11

Expected behaviour

Running "Organise Imports" from the command palette invokes isort and fixes import order

Actual behaviour

No change to file, no output

Logs

Pylance:

User belongs to experiment group 'AlwaysDisplayTestExplorer - experiment'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'AA_testing - experiment'
User belongs to experiment group 'LocalZMQKernel - experiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'RunByLine - experiment'
User belongs to experiment group 'CustomEditorSupport - control'
User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonTipPromptWording'
> conda --version
> python3.7 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda info --json
Error 2020-09-16 14:20:24: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'vscode-remote://wsl+ubuntu2/home/lex/.config/Code/User/settings.json' (EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, open '/home/lex/.config/Code/User/settings.json')
	at _handleError (/home/lex/.vscode-server/bin/e790b931385d72cf5669fcefc51cdf65990efa5d/out/vs/server/remoteExtensionHostProcess.js:730:74)
	at processTicksAndRejections (internal/process/task_queues.js:94:5)
	at async v.readText (/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:1:495755)
	at async p.doesFileNeedToBeFixed (/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:953520)
	at async /home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952647
	at async Promise.all (index 0)
	at async p.getFilesToBeFixed (/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952593)
	at async p.updateTestSettings (/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952220)] {
  code: 'FileNotFound',
  name: 'EntryNotFound (FileSystemError)'
}
Error 2020-09-16 14:20:24: Failed to get interpreter information for '/home/lex/.pyenv/shims/python3.8' [Error: Command failed: "/home/lex/.pyenv/shims/python3.8" "/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py" "/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/interpreterInfo.py"
pyenv: python3.8: command not found

The `python3.8' command exists in these Python versions:
  3.8.4

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

	at ChildProcess.exithandler (child_process.js:295:12)
	at ChildProcess.emit (events.js:223:5)
	at maybeClose (internal/child_process.js:1021:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)] {
  killed: false,
  code: 127,
  signal: null,
  cmd: '"/home/lex/.pyenv/shims/python3.8" "/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py" "/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/interpreterInfo.py"'
}
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
Starting Pylance language server.
Python interpreter path: ./.venv/bin/python3.6
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> conda --version
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
##########Linting Output - flake8##########
4,1,I,I004:isort found an unexpected blank line in imports
6,1,I,I001:isort found an import in the wrong position
7,1,I,I004:isort found an unexpected blank line in imports
8,101,E,E501:line too long (102 > 100 characters)
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/sortImports.py - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/sortImports.py - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/sortImports.py - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/sortImports.py - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py black --diff --quiet ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py black --diff --quiet ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
##########Linting Output - flake8##########
4,1,I,I004:isort found an unexpected blank line in imports
6,1,I,I001:isort found an import in the wrong position
7,1,I,I004:isort found an unexpected blank line in imports
8,101,E,E501:line too long (102 > 100 characters)

Microsoft (where it works):

User belongs to experiment group 'AlwaysDisplayTestExplorer - experiment'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'AA_testing - experiment'
User belongs to experiment group 'LocalZMQKernel - experiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'RunByLine - experiment'
User belongs to experiment group 'CustomEditorSupport - control'
User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonTipPromptWording'
> conda --version
> conda info --json
> python3.7 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Error 2020-09-16 14:22:45: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'vscode-remote://wsl+ubuntu2/home/lex/.config/Code/User/settings.json' (EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, open '/home/lex/.config/Code/User/settings.json')
	at _handleError (/home/lex/.vscode-server/bin/e790b931385d72cf5669fcefc51cdf65990efa5d/out/vs/server/remoteExtensionHostProcess.js:730:74)
	at processTicksAndRejections (internal/process/task_queues.js:94:5)
	at async v.readText (/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:1:495755)
	at async p.doesFileNeedToBeFixed (/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:953520)
	at async /home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952647
	at async Promise.all (index 0)
	at async p.getFilesToBeFixed (/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952593)
	at async p.updateTestSettings (/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952220)] {
  code: 'FileNotFound',
  name: 'EntryNotFound (FileSystemError)'
}
Error 2020-09-16 14:22:45: Failed to get interpreter information for '/home/lex/.pyenv/shims/python3.8' [Error: Command failed: "/home/lex/.pyenv/shims/python3.8" "/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py" "/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/interpreterInfo.py"
pyenv: python3.8: command not found

The `python3.8' command exists in these Python versions:
  3.8.4

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

	at ChildProcess.exithandler (child_process.js:295:12)
	at ChildProcess.emit (events.js:223:5)
	at maybeClose (internal/child_process.js:1021:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)] {
  killed: false,
  code: 127,
  signal: null,
  cmd: '"/home/lex/.pyenv/shims/python3.8" "/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py" "/home/lex/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/interpreterInfo.py"'
}
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
Starting Microsoft Python language server.
Python interpreter path: ./.venv/bin/python3.6
> conda --version
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
##########Linting Output - flake8##########
4,1,I,I004:isort found an unexpected blank line in imports
6,1,I,I001:isort found an import in the wrong position
7,1,I,I004:isort found an unexpected blank line in imports
8,101,E,E501:line too long (102 > 100 characters)
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/sortImports.py - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/sortImports.py - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py black --diff --quiet ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py.782ed9ea092c1f1aad5ec65bfe1037d5.tmp
cwd: ~/projects/data-lake
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py black --diff --quiet ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py.782ed9ea092c1f1aad5ec65bfe1037d5.tmp
cwd: ~/projects/data-lake
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
> ~/projects/data-lake/.venv/bin/python3.6 ~/.vscode-server/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
cwd: ~/projects/data-lake
##########Linting Output - flake8##########
6,101,E,E501:line too long (102 > 100 characters)

Code Snippet / Additional information

from unittest.mock import Mock

import pytest

from pyspark.sql.session import SparkSession
from _pytest.monkeypatch import MonkeyPatch

from retailer_service_retailer_facts_compactor.glue.retailer_service_retailer_facts_compactor import (
    main,
)

isort exists, is installed in the virtualenv and is configured via pyproject.toml.

@jakebailey
Copy link
Member

We don't handle the organize imports command, the core extension does. I'll move this issue there as it's the one running isort.

@jakebailey jakebailey transferred this issue from microsoft/pylance-release Sep 16, 2020
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Sep 16, 2020
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug triage labels Sep 17, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 17, 2020
@kimadeline
Copy link

Hello @Lexicality, thank you for reaching out.

You don't need to install isort yourself since we ship it with the extension. If you use the built-in one, we recently fixed an issue with it (#13832) but it hasn't made it into the release yet, can you try using the Insiders version of the extension?

Thanks!

@Lexicality
Copy link
Author

Apologies, I'm not sure how to install the insiders version, is there a guide somewhere? It only offers me v2020.8.109390 in "Install Another Version"

@kimadeline
Copy link

Sorry about that!

To opt-in this program, open the command palette (View > Command Palette… or Ctrl+Shift+P) and select either "Python: Switch to Insiders Weekly Channel" or "Python: Switch to Insiders Daily Channel".

Another way to do it is to open the settings page (File > Preferences > Settings), look for "Python: Insiders Channel" and set the channel to "daily" or "weekly":

image

A download of the Insiders version of the extension will then start (you can follow its progress in the status bar), and we will prompt you to reload VS Code once it finishes.

@Lexicality
Copy link
Author

Hmm, that works but it produces a different output than the local version of isort which causes the lint to break

@Lexicality
Copy link
Author

Lexicality commented Sep 18, 2020

I just tried using my local isort using the workspace settings and that didn't seem to work at all

> isort - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
Error: write EPIPE
Error 2020-09-18 18:24:56: Failed to format imports for '/home/lex/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py'. [Error: write EPIPE
	at afterWriteDispatched (internal/stream_base_commons.js:149:25)
	at writeGeneric (internal/stream_base_commons.js:140:3)
	at Socket._writeGeneric (net.js:776:11)
	at Socket._write (net.js:788:8)
	at doWrite (_stream_writable.js:435:12)
	at writeOrBuffer (_stream_writable.js:419:5)
	at Socket.Writable.write (_stream_writable.js:309:11)
	at S.communicateWithIsortProcess (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:905588)
	at t.pythonExecutionFactory.create.resource (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:905047)
	at S._provideDocumentSortImportsEdits (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:903088)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (internal/process/task_queues.js:94:5)] {
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write'
}
> ${projectRoot}/.venv/bin/isort - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
Error: write EPIPE
Error 2020-09-18 18:25:23: Failed to format imports for '/home/lex/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py'. [Error: write EPIPE
	at afterWriteDispatched (internal/stream_base_commons.js:149:25)
	at writeGeneric (internal/stream_base_commons.js:140:3)
	at Socket._writeGeneric (net.js:776:11)
	at Socket._write (net.js:788:8)
	at doWrite (_stream_writable.js:435:12)
	at writeOrBuffer (_stream_writable.js:419:5)
	at Socket.Writable.write (_stream_writable.js:309:11)
	at S.communicateWithIsortProcess (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:905588)
	at t.pythonExecutionFactory.create.resource (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:905047)
	at S._provideDocumentSortImportsEdits (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:903088)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (internal/process/task_queues.js:94:5)] {
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write'
}
> .venv/bin/isort - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
Error: write EPIPE
Error 2020-09-18 18:25:43: Failed to format imports for '/home/lex/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py'. [Error: write EPIPE
	at afterWriteDispatched (internal/stream_base_commons.js:149:25)
	at writeGeneric (internal/stream_base_commons.js:140:3)
	at Socket._writeGeneric (net.js:776:11)
	at Socket._write (net.js:788:8)
	at doWrite (_stream_writable.js:435:12)
	at writeOrBuffer (_stream_writable.js:419:5)
	at Socket.Writable.write (_stream_writable.js:309:11)
	at S.communicateWithIsortProcess (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:905588)
	at t.pythonExecutionFactory.create.resource (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:905047)
	at S._provideDocumentSortImportsEdits (/home/lex/.vscode-server/extensions/ms-python.python-2020.9.106814-dev/out/client/extension.js:56:903088)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (internal/process/task_queues.js:94:5)] {
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write'
}

@kimadeline
Copy link

kimadeline commented Sep 18, 2020

What version of isort do you use locally? You shouldn't need to install it yourself since we ship it with the extension.

@Lexicality
Copy link
Author

Apologies for the delay in getting back to you, I was on holiday.
We use 4.3.21 locally and I need to install it or the linting won't work.

@kimadeline
Copy link

No worries!

The issue you're encountering sounds very similar to #13063, which is a duplicate of #7042.

Can you try the workaround mentioned in #7042 by specifying the full path to isort to the setting: "python.sortImports.path": "/home/username/project/.venv/bin/isort"?

"python.sortImports.path": "${workspaceFolder}/.venv/bin/isort" works as well according to others.

@Lexicality
Copy link
Author

I get

> ~/projects/data-lake/.venv/bin/isort - --diff
cwd: ~/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests
Error 2020-09-23 10:25:31: /home/lex/projects/data-lake/.venv/lib/python3.6/site-packages/setuptools/distutils_patch.py:26: 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.
  "Distutils was imported before Setuptools. This usage is discouraged "

/home/lex/projects/data-lake/.venv/lib/python3.6/site-packages/setuptools/distutils_patch.py:26: 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.
  "Distutils was imported before Setuptools. This usage is discouraged "

Error 2020-09-23 10:25:31: Failed to format imports for '/home/lex/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py'. /home/lex/projects/data-lake/.venv/lib/python3.6/site-packages/setuptools/distutils_patch.py:26: 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.
  "Distutils was imported before Setuptools. This usage is discouraged "

if I do that, which is similar to what happens if I run it in terminal:

$ .venv/bin/isort -y src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py
/home/lex/projects/data-lake/.venv/lib/python3.6/site-packages/setuptools/distutils_patch.py:26: 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.
  "Distutils was imported before Setuptools. This usage is discouraged "
Fixing /home/lex/projects/data-lake/src/retailer_service_retailer_facts_compactor/tests/test_retailer_service_retailer_facts_compactor.py

however it correctly formats the file when I run it in terminal.

I found #12949 related to this, but I'm not sure why it works in bash while it doesn't work in vscode

@kimadeline
Copy link

We expect isort to return a diff of the code we passed to it, and anything that isn't part of a diff is flagged as a failure to sort imports. As such not only do we discard any possible changes that were sent besides the message (that's why no changes are applied when ran in VS Code), but we also display it as an error:

} catch (error) {
const message = typeof error === 'string' ? error : error.message ? error.message : error;
const outputChannel = this.serviceContainer.get<IOutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
outputChannel.appendLine(error);
traceError(`Failed to format imports for '${uri.fsPath}'.`, error);
this.shell.showErrorMessage(message).then(noop, noop);
}

Have you tried downgrading setuptools like suggested in #12949?

@Lexicality
Copy link
Author

Ah, I get you. Yes, running pip install setuptools==49.1.3 in my virtualenv seems to have fixed the problem.

Sorry for all the confusion, I'm not really a python person.

Would it be possible to improve the error messages caused when isort fails to explain the problem? I would normally expect a warning not to fail an action.

Thanks for helping!

@kimadeline
Copy link

No problem, glad we're getting it sorted out, and thank you for trying all the workarounds!

Would it be possible to improve the error messages caused when isort fails to explain the problem? I would normally expect a warning not to fail an action.

I opened a feature request on your behalf: #14066, feel free to leave a comment there if you want to provide more details. You can also help us prioritize it by upvoting it 🙂

Going to close this issue and mark it as resolved, but if you encounter any problem later down the road let us know in the comments and we can reopen it.

Thank you!

@ghost ghost removed the triage label Sep 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

4 participants