DamnWidget / anaconda

Anaconda turns your Sublime Text 3 in a full featured Python development IDE including autocompletion, code linting, IDE features, autopep8 formating, McCabe complexity checker Vagrant and Docker support for Sublime Text 3 using Jedi, PyFlakes, pep8, MyPy, PyLint, pep257 and McCabe that will never freeze your Sublime Text 3
http://damnwidget.github.io/anaconda/
GNU General Public License v3.0
2.22k stars 259 forks source link

Anaconda server crash due to Jedi version #944

Open RaytingSec opened 1 month ago

RaytingSec commented 1 month ago

Expected Behaviour

Open a python file with ST, Anaconda provides it's features such as docs, autocomplete, and linting

Actual Behaviour

ConnectionRefusedError is thrown

Steps to Reproduce

ST3, Anaconda and OS versions

ST3 Console Logs

See Troubleshooting section

Anaconda's JsonServer Logs

Note: Anaconda's JsonServer logs can be found in:

See Troubleshooting section

Troubleshooting

TLDR, it seems the Jedi version need to be bumped.

For a while now, Anaconda's server is unable to start up and I get this as part of the error in ST console:

ConnectionRefusedError: [Errno 111] Connection refused

I'm unable to find a detailed message unless I run jsonserver.py myself, then I can see more detailed message like stacktrace:

2024-10-19 02:08:32,691: ERROR   : too many values to unpack (expected 2)
2024-10-19 02:08:32,691: ERROR   : Traceback (most recent call last):
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py", line 112, in found_terminator
    self.handle_command(
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py", line 144, in handle_command
    ).run()
      ^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 28, in run
    super(JediHandler, self).run()
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/lib/anaconda_handler.py", line 49, in run
    command(**kwargs)
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 123, in doc
    Doc(
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/commands/doc.py", line 34, in __init__
    super(Doc, self).__init__(callback, uid)
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/commands/base.py", line 14, in __init__
    self.run()
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/commands/doc.py", line 58, in run
    else self._html(definition)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/commands/doc.py", line 84, in _html
    html.unescape(definition.docstring()), quote=False
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/api/classes.py", line 301, in docstring
    doc = self._get_docstring()
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/api/classes.py", line 312, in _get_docstring
    return self._name.py__doc__()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/names.py", line 236, in py__doc__
    names = convert_names([self], prefer_stub_to_compiled=False)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/gradual/conversion.py", line 154, in convert_names
    return _try_stub_to_python_names(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/utils.py", line 16, in wrapper
    return list(func(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/gradual/conversion.py", line 83, in _try_stub_to_python_names
    converted_names = converted.goto(name.get_public_name())
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/base_value.py", line 493, in goto
    return reduce(add, [c.goto(*args, **kwargs) for c in self._set], [])
                        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/base_value.py", line 72, in goto
    names = finder.filter_name(filters, name_or_str)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/finder.py", line 36, in filter_name
    names = filter.get(string_name)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/compiled/value.py", line 435, in get
    return self._get(
           ^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/compiled/value.py", line 454, in _get
    has_attribute, is_descriptor = allowed_getattr_callback(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

After much digging and troubleshooting, I found when I install Jedi via pip, it's the latest version jedi-0.19.1 and some of the code such as allowed_getattr_callback() involved in the too many values to unpack has changed. It returns three instead of two.

I attempted a crude patch by rsync from .venv/lib/python3.12/site-packages/jedi/ to ~/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/, and Anaconda appears to be working fine now. I have linting and autocomplete again, and I no longer see errors in my ~/.local/share/anaconda/ logs.

Edit: I can open a PR, or try checking for other library updates. But how can I test the changes, or who is able to test it? Long time user and happy to contribute a bit to a tool I love.

RaytingSec commented 1 month ago

There's a second problem involving virtual environments, where the JSON server doesn't start and results in the connection refused error:

anacondaST3: ERROR - Anaconda worker could not start because:

can not connect to /home/rayting/.local/share/anaconda/run/anacondatest/anaconda.sock. tried to connect 21 times during 2.0 seconds

check that there is Python process executing the anaconda jsonserver.py script running in your system. If there is, check that the Unix Domain Socket file /home/rayting/.local/share/anaconda/run/anacondatest/anaconda.sock exists and that you can connect to it writing the following script in your Sublime Text 3 console:

import socket; socket.socket(socket.AF_UNIX, socket.SOCK_STREAM).connect(/home/rayting/.local/share/anaconda/run/anacondatest/anaconda.sock)

If anaconda works just fine after you received this error and the command above worked you can make anaconda to do not show you this error anymore setting the 'swallow_startup_errors' to 'true' in your configuration file.

Steps to reproduce