InSyncWithFoo / pyright-for-pycharm

Pyright integration for PyCharm
https://insyncwithfoo.github.io/pyright-for-pycharm/
MIT License
49 stars 0 forks source link

Not getting any Pyright warnings #39

Closed shner-elmo closed 3 months ago

shner-elmo commented 3 months ago

What happened?

Hey, so I followed the docs to install Pyright for PyCharm (community version), but I don't see any warnings/errors on this code: image

I'm not sure if I didn't install it correctly or there is a bug...

Steps to reproduce

Relevant log output or stack trace

No response

Operating system

Linux

InSyncWithFoo commented 3 months ago

Configure the path: pypoetry/virtualenvs/project-name/bin/pyright-python-langserver (I tried all 3 pyright executables)

There should be these 4 executables in your virtual environment directory: pyright, pyright-python, pyright-langserver and pyright-python-langserver. You should only use either the first or the second. Could you confirm that this was the case, and that the hint said "File found"?

shner-elmo commented 3 months ago

First of all, thanks for the swift response!

I tried all four; pyright and pyright-python were found, but for pyright-langserver and pyright-python-langserver the hint said: "Unrecognized filename (ignore this notice if you are sure it is correct)".

but anyways none of the 4 are working

InSyncWithFoo commented 3 months ago

Without the log, it is hard to say, but this might be the same problem that I got during development: the annotator is not invoked reliably.

There's a way to check this:

  1. Go to Editor | General | Editor Tabs and enable Mark modified.
  2. Save, then start editing your file. Every edit will cause a blue dot (new UI) to appear next to the file's name.
  3. If the annotator is invoked, it will save all files and cause that blue dot to quickly disappear. Otherwise, it will remain until your focus is switched to somewhere else (the default behaviour).

I never knew the cause, but I managed to "fix" it by clearing my sandbox (i.e. reinstall/reset the IDE).

shner-elmo commented 3 months ago

Without the log, it is hard to say

How can I find it?

I can confirm that I now see the dot when I modify the file, and it disappears right away. However I don't see any Pyright warnings.

Is the only option left is to reinstall the IDE?

InSyncWithFoo commented 3 months ago

How can I find it?

Go to Help | Show Log in Explorer.

Typically, look for lines with PyrightRunner - Running. Such a line should be followed by another with PyrightRunner - Output.

If the provided executable cannot be run, you should find some ProcessNotCreatedExceptions in there.

Is the only option left is to reinstall the IDE?

I'm not saying it's the only option, just that that's what I did and I haven't managed to reproduce the problem since then. Also, in case you choose to do so: All settings and such are exported beforehand and can be reimported in a jiffy; I reset my own IDEs multiple times and the process is relatively painless.

shner-elmo commented 3 months ago

Ok thanks for the explanation, I will try that tomorrow

shner-elmo commented 3 months ago

From the logs it seems like it is indeed running, and there is no ProcessNotCreatedException.

Here is the output of grep -ir "pyright" ~/.cache/JetBrains/PyCharmCE2024.1/log if you're interested.

shner-elmo commented 3 months ago

I reset the settings and reinstalled the IDE, still not working :(

InSyncWithFoo commented 3 months ago

I am indeed very interested to see the log. Despite being incomplete, it shows that the problem happened during deserializing Pyright's output:

idea.log:2024-05-23 13:22:54,272 [143723506] SEVERE - #c.i.c.d.i.ExternalToolPass - IdeaLoggingEvent[message=ExternalToolPass: , throwable=com.intellij.diagnostic.PluginException: annotator: com.insyncwithfoo.pyright.PyrightExternalAnnotator@4c5cc416 (class com.insyncwithfoo.pyright.PyrightExternalAnnotator) [Plugin: com.insyncwithfoo.pyright]
idea.log:   at com.insyncwithfoo.pyright.PyrightOutput$$serializer.deserialize(PyrightDiagnostic.kt:7)
idea.log:   at com.insyncwithfoo.pyright.PyrightOutput$$serializer.deserialize(PyrightDiagnostic.kt:7)
idea.log:   at com.insyncwithfoo.pyright.runner.PyrightRunner.parseOutput(Runner.kt:86)
idea.log:   at com.insyncwithfoo.pyright.runner.PyrightRunner.runAndLogOutput(Runner.kt:55)
idea.log:   at com.insyncwithfoo.pyright.runner.PyrightRunner.run(Runner.kt:40)
idea.log:   at com.insyncwithfoo.pyright.PyrightExternalAnnotator.doAnnotate(PyrightExternalAnnotator.kt:178)
idea.log:   at com.insyncwithfoo.pyright.PyrightExternalAnnotator.doAnnotate(PyrightExternalAnnotator.kt:146)

Could you show me the output of the following command, which is what was run? It should be valid JSON and follows the interfaces defined here.

$ /home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/bin/pyright-python /home/shneor/Desktop/projects/python/personal/TradingView-Screener/src/tradingview_screener/query.py --outputjson --project /home/shneor/Desktop/projects/python/personal/TradingView-Screener --pythonpath /home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/bin/python

In the meanwhile, I will add some error-catching logic so that things like this don't silently pass.

shner-elmo commented 3 months ago

This is the output:

/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/nodeenv.py:26: DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13
  import pipes
/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/nodeenv.py:48: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import parse_version
 * Environment already exists: /home/shneor/.cache/pyright-python/nodeenv
Traceback (most recent call last):
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/bin/pyright-python", line 8, in <module>
    sys.exit(entrypoint())
             ^^^^^^^^^^^^
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/pyright/cli.py", line 34, in entrypoint
    sys.exit(main(sys.argv[1:]))
             ^^^^^^^^^^^^^^^^^^
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/pyright/cli.py", line 19, in main
    return run(*args, **kwargs).returncode
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/pyright/cli.py", line 25, in run
    pkg_dir = install_pyright(args, quiet=None)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/pyright/_utils.py", line 64, in install_pyright
    node.run(
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/pyright/node.py", line 105, in run
    binary = _ensure_available(target)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/pyright/node.py", line 38, in _ensure_available
    return Binary(path=_ensure_node_env(target), strategy=Strategy.NODEENV)
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/pyright/node.py", line 65, in _ensure_node_env
    _install_node_env()
  File "/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/lib/python3.11/site-packages/pyright/node.py", line 98, in _install_node_env
    subprocess.run(args, check=True)
  File "/home/shneor/.pyenv/versions/3.11.4/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/home/shneor/.cache/pypoetry/virtualenvs/tradingview-screener-5WV6isL9-py3.11/bin/python', '-m', 'nodeenv', '/home/shneor/.cache/pyright-python/nodeenv']' returned non-zero exit status 2.
InSyncWithFoo commented 3 months ago

No wonder there are no diagnostics: the executable failed outright.

This is not a problem with the plugin, and I'm sorry that I can't provide further support, but you could try reinstalling Pyright (via npm?) as a start.

The new error-checking logic will be included in v0.5.0, to be released sometime next week or the week after that.

shner-elmo commented 3 months ago

Ah yes! its working now:

image

Turns out that doing pip install pyright isn't enough. You need to install npm and node. FYI it might be easier to debug pyright issues by just invoking the executable: $ pyright and googling the rest...

Thanks again for all the help @InSyncWithFoo