python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.94k stars 194 forks source link

Code actions are failing because of unsupported python version #583

Open rukbotto opened 3 months ago

rukbotto commented 3 months ago

Today, I tried to use code actions to insert a new import statement and got the following exception:

[ERROR][2024-07-23 18:30:12] .../vim/lsp/rpc.lua:734    "rpc"   "/Users/xyz/.local/share/nvim/mason/bin/pylsp"  "stderr"    "2024-07-23 18:30:12,972 -05 - WARNING - pylsp.config.config - Failed to load hook pylsp_code_actions: Python version 3.12 is currently not supported.
Traceback (most recent call last):
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/grammar.py\", line 246, in load_grammar
    return _loaded_grammars[path]
           ~~~~~~~~~~~~~~~~^^^^^^
KeyError: '/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/python/grammar312.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/grammar.py\", line 249, in load_grammar
    with open(path) as f:
         ^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/python/grammar312.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/config/config.py\", line 39, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_manager.py\", line 480, in traced_hookexec
    return outcome.get_result()
           ^^^^^^^^^^^^^^^^^^^^
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_result.py\", line 100, in get_result
    raise exc.with_traceback(exc.__traceback__)
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_result.py\", line 62, in from_call
    result = func()
             ^^^^^^
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_manager.py\", line 477, in <lambda>
    lambda: oldcall(hook_name, hook_impls, caller_kwargs, firstresult)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_callers.py\", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_callers.py\", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/plugins/rope_autoimport.py\", line 342, in pylsp_code_actions
    word = get_name_or_module(document, diagnostic)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/plugins/rope_autoimport.py\", line 295, in get_name_or_module
    parso.parse(document.lines[start[\"line\"]])
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/__init__.py\", line 57, in parse
    grammar = load_grammar(version=version)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/grammar.py\", line 260, in load_grammar
    return load_grammar(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/xyz/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/grammar.py\", line 256, in load_grammar
    raise NotImplementedError(message)
NotImplementedError: Python version 3.12 is currently not supported.
"

This happened after I updated the neovim plugins I have installed.

This is the output of pip freeze within the virtualenv used by the LSP server:

astroid==3.2.2
autopep8==2.0.4
black==24.4.2
click==8.1.7
dill==0.3.8
docstring-to-markdown==0.15
flake8==7.0.0
importlib_metadata==8.0.0
isort==5.13.2
jedi==0.17.2
mccabe==0.7.0
mypy==1.10.1
mypy-extensions==1.0.0
packaging==24.1
parso==0.7.1
pathspec==0.12.1
platformdirs==4.2.2
pluggy==1.5.0
pycodestyle==2.11.1
pydocstyle==6.3.0
pyflakes==3.2.0
pylint==3.2.5
pyls-flake8==0.4.0
pylsp-mypy==0.6.8
pylsp-rope==0.1.16
python-jsonrpc-server==0.4.0
python-language-server==0.36.2
python-lsp-black==2.0.0
python-lsp-isort==0.1
python-lsp-jsonrpc==1.1.2
python-lsp-server==1.11.0
pytoolconfig==1.3.1
rope==1.13.0
snowballstemmer==2.2.0
toml==0.10.2
tomli==2.0.1
tomlkit==0.12.5
typing_extensions==4.12.2
ujson==5.10.0
whatthepatch==1.0.5
yapf==0.40.2
zipp==3.19.2

And this is the LSP configuration I'm currently using:

lspconfig.pylsp.setup({
  settings = {
    pylsp = {
      configurationSources = "flake8",
      plugins = {
        pylint = { enabled = false },
        autopep8 = { enabled = false },
        pycodestyle = { enabled = false },
        mccabe = { enabled = false },
        pyflakes = { enabled = false },
        yapf = { enabled = false },
        flake8 = { enabled = true },
        black = { enabled = true },
        isort = { enabled = true },
        pylsp_mypy = { enabled = true },
        rope_autoimport = { enabled = true },
      },
    },
  },
})

Currently using nvim-lspconfig to configure my LSPs, on a Mac machine.

rukbotto commented 3 months ago

This is a no-op. After updating the libs installed in my system, the code actions started to work again.

rukbotto commented 3 months ago

Reopening. Although code actions now work for me when I want to extract variables or perform other common refactoring operations, when I try to import a library (using rope_autoimport), the same error keeps triggering:

[ERROR][2024-07-31 10:55:39] .../vim/lsp/rpc.lua:770    "rpc"   "/Users/rukbotto/.local/share/nvim/mason/bin/pylsp" "stderr"    "2024-07-31 10:55:39,437 -05 - WARNING - pylsp.config.config - Failed to load hook pylsp_code_actions: Python version 3.12 is currently not supported.
Traceback (most recent call last):
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/grammar.py\", line 246, in load_grammar
    return _loaded_grammars[path]
           ~~~~~~~~~~~~~~~~^^^^^^
KeyError: '/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/python/grammar312.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/grammar.py\", line 249, in load_grammar
    with open(path) as f:
         ^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/python/grammar312.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/config/config.py\", line 39, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_manager.py\", line 480, in traced_hookexec
    return outcome.get_result()
           ^^^^^^^^^^^^^^^^^^^^
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_result.py\", line 100, in get_result
    raise exc.with_traceback(exc.__traceback__)
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_result.py\", line 62, in from_call
    result = func()
             ^^^^^^
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_manager.py\", line 477, in <lambda>
    lambda: oldcall(hook_name, hook_impls, caller_kwargs, firstresult)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_callers.py\", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pluggy/_callers.py\", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/plugins/rope_autoimport.py\", line 342, in pylsp_code_actions
    word = get_name_or_module(document, diagnostic)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/pylsp/plugins/rope_autoimport.py\", line 295, in get_name_or_module
    parso.parse(document.lines[start[\"line\"]])
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/__init__.py\", line 57, in parse
    grammar = load_grammar(version=version)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/grammar.py\", line 260, in load_grammar
    return load_grammar(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File \"/Users/rukbotto/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.12/site-packages/parso/grammar.py\", line 256, in load_grammar
    raise NotImplementedError(message)
NotImplementedError: Python version 3.12 is currently not supported.
"