fannheyward / coc-pyright

Pyright extension for coc.nvim
MIT License
1.28k stars 46 forks source link

Better way to detect tools' path #919

Open fannheyward opened 1 year ago

fannheyward commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.