Repository: astral-sh/ruff-vscode

Issue #323: `importStrategy: fromEnvironment` fallback doesn't work if the environment's Ruff is too old
Created: 2023-11-01T22:19:15Z
Hello! I've said it before, but thanks again for Ruff (and also for this excellent VS Code extension) 🙂
I'm filing this just in case it isn't the intended behavior, although I can see a strong argument for it being fine. Please close with extreme prejudice if it's working as intended!
Actual Behavior
I noticed this behavior while trying to trying to use ruff-vscode across a few different repositories and virtual environments, both with and without ruff installed.
With importStrategy: fromEnvironment:

If I use ruff-vscode with an activated venv that does not have ruff inside of it, the extension works as expected (falls back to its bundled copy of ruff)
If I use ruff-vscode with an activated venv that does have ruff (but a too-old ruff, like 0.0.254), the extension produces a warning telling me that the local ruff is too old:


With that warning, no formatting is performed.
Expected Behavior
In this situation, I expected ruff-vscode to fall back on its bundled version after detecting that the virtual environment's version is too old. However, I can see an argument for this being too clever, especially given the workarounds below.
Workarounds
The following workarounds work:

Just using importStrategy: fromBundle. This works as expected!
Upgrading my venv's copy of ruff, which I should have done a while ago.

Other information
Host information (I believe this isn't a factor in this case, but for completeness):

Current Ruff versions: 0.1.2 (bundled) and 0.0.254 (in venv when I noticed this)
OS: macOS Sonoma, Python 3.12.0

Duplicate issue #476: Better notification when used Ruff not compatible to extension.
Created: 2024-05-23T10:06:25Z
Notifications on using Ruff v0.3.0 with ruff.nativeServer settings enabled:

Output
2024-05-23 13:26:39.572 [info] Server: Stop requested
2024-05-23 13:26:39.585 [info] Server run command: c:\Users\User\Desktop\test\.venv\Scripts\python.exe c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py server --preview
2024-05-23 13:26:39.585 [info] Server: Start requested.
2024-05-23 13:26:39.591 [info] 2024-05-23 13:26:39,580 INFO Shutting down the server
2024-05-23 13:26:39,580 INFO Closing the event loop.

2024-05-23 13:26:39.759 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:39.767 [info] [Error - 1:26:39 PM] Server initialization failed.
2024-05-23 13:26:39.767 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:39.767 [info] [Info  - 1:26:39 PM] Connection to server got closed. Server will restart.
2024-05-23 13:26:39.767 [info] true
2024-05-23 13:26:39.768 [info] [Error - 1:26:39 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:39.768 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:39.914 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:39.923 [info] [Error - 1:26:39 PM] Server initialization failed.
2024-05-23 13:26:39.923 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:39.923 [info] [Info  - 1:26:39 PM] Connection to server got closed. Server will restart.
2024-05-23 13:26:39.923 [info] true
2024-05-23 13:26:39.923 [info] [Error - 1:26:39 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:39.924 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:39.924 [error] Server: Start failed: Error: Pending response rejected since connection got disposed
2024-05-23 13:26:40.061 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:40.069 [info] [Error - 1:26:40 PM] Server initialization failed.
2024-05-23 13:26:40.069 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.069 [info] [Info  - 1:26:40 PM] Connection to server got closed. Server will restart.
2024-05-23 13:26:40.069 [info] true
2024-05-23 13:26:40.069 [info] [Error - 1:26:40 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:40.069 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.069 [info] [Error - 1:26:40 PM] Restarting server failed
2024-05-23 13:26:40.069 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.212 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:40.220 [info] [Error - 1:26:40 PM] Server initialization failed.
2024-05-23 13:26:40.220 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.220 [info] [Info  - 1:26:40 PM] Connection to server got closed. Server will restart.
2024-05-23 13:26:40.220 [info] true
2024-05-23 13:26:40.220 [info] [Error - 1:26:40 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:40.220 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.221 [info] [Error - 1:26:40 PM] Restarting server failed
2024-05-23 13:26:40.221 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.360 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:40.368 [info] [Error - 1:26:40 PM] Server initialization failed.
2024-05-23 13:26:40.368 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.368 [info] [Error - 1:26:40 PM] The Ruff server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
2024-05-23 13:26:40.368 [info] [Error - 1:26:40 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:40.368 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.369 [info] [Error - 1:26:40 PM] Restarting server failed
2024-05-23 13:26:40.369 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097

Closing comment (2024-05-24T19:27:51Z): Also related to #323. I expected to get Ruff is too old notification at here.