coc-pyright
coc-pyright copied to clipboard
Better way to detect tools' path
Couldn't the logic be something like this? If
pythonPath
has been resolved to something in a virtualenv (e.g..venv/bin/python
). Storeconst venvBinPath = path.dirname(pythonPath)
. And then when runningmypy
you first trypath.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
Currently steps:
- get tool's path from setting,
execPath = mypy
- use
which
to get full exec path-
execPath = /full/path/to/global/mypy
- or
execPath = /path/to/project/.venv/bin/mypy
-
- now basename never equal to execPath, module name is undefined
- run in sub process mode,
/full/path/to/mypy xxx
This detection can use global and local tools, but breaks module mode.
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.