astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.06k stars 53 forks source link

Validate Python interpreter version for native server #516

Closed dhruvmanila closed 3 months ago

dhruvmanila commented 3 months ago

Summary

I'm not sure why this check was removed looking back at https://github.com/astral-sh/ruff-vscode/pull/431, but this validation should be done for both native server and ruff-lsp. Both uses a Python script which requires Python 3.7 or later and ruff in general also supports 3.7 and later.

Without this change, if someone were to use Python 3.6, the extension would give the following error:

2024-07-05 09:26:21.378 [error] Error while trying to find the Ruff binary: Error: Command failed: /Users/dhruv/.pyenv/versions/3.6.15/bin/python /Users/dhruv/work/astral/ruff-vscode/bundled/tool/find_ruff_binary_path.py
Traceback (most recent call last):
  File "/Users/dhruv/work/astral/ruff-vscode/bundled/tool/find_ruff_binary_path.py", line 33, in <module>
    ruff_binary_path = find_ruff_binary_path()
  File "/Users/dhruv/work/astral/ruff-vscode/bundled/tool/find_ruff_binary_path.py", line 20, in find_ruff_binary_path
    elif sys.platform == "darwin" and sys._framework:
AttributeError: module 'sys' has no attribute '_framework'

Test Plan

The above error still occurs and the fix for that is in a follow-up PR (https://github.com/astral-sh/ruff-vscode/pull/517).

Using the below settings:

{
  "ruff.nativeServer":true,
  "ruff.interpreter": ["/Users/dhruv/.pyenv/versions/3.6.15/bin/python"]
}

The logs shows that the version isn't supported:

2024-07-05 09:27:38.086 [error] Python version 3.6 is not supported.
2024-07-05 09:27:38.086 [error] Selected python path: /Users/dhruv/.pyenv/versions/3.6.15/bin/python
2024-07-05 09:27:38.086 [error] Supported versions are 3.7 and above.