coc-pyright icon indicating copy to clipboard operation
coc-pyright copied to clipboard

Better way to detect tools' path

Open fannheyward opened this issue 1 year ago • 2 comments

Couldn't the logic be something like this? If pythonPath has been resolved to something in a virtualenv (e.g. .venv/bin/python). Store const venvBinPath = path.dirname(pythonPath). And then when running mypy you first try path.join(venvBinPath, 'mypy'). And if that fails, look in $PATH?

You could maybe even do that logic during startup and save the absolute path to the binary so you don't have to run a subprocess twice in the global case.

Originally posted by @lithammer in https://github.com/fannheyward/coc-pyright/issues/917#issuecomment-1514523766

fannheyward avatar Apr 20 '23 02:04 fannheyward

Currently steps:

  1. get tool's path from setting, execPath = mypy
  2. use which to get full exec path
    • execPath = /full/path/to/global/mypy
    • or execPath = /path/to/project/.venv/bin/mypy
  3. now basename never equal to execPath, module name is undefined
  4. run in sub process mode, /full/path/to/mypy xxx

This detection can use global and local tools, but breaks module mode.

fannheyward avatar Apr 20 '23 02:04 fannheyward

Another issue https://github.com/fannheyward/coc-pyright/issues/901, rope can only be run in module mode, the detected Python bin must install rope to use.

fannheyward avatar Apr 20 '23 02:04 fannheyward