python-lsp / pylsp-mypy

Mypy plugin for the Python LSP Server.
MIT License
118 stars 35 forks source link

Improve support for virtual env. (#26) #27

Closed sathlan closed 1 year ago

sathlan commented 2 years ago

When VIRTUAL_ENV variable is present in the environment, use "python mypy" instead of "mypy" so that library loaded in the VIRTUAL_ENV get correctly loaded. This works because python is always present is the VIRTUAL_ENV, but requires that mypy to be present is the directory where the caller is. In the context of the python-lsp-server and pipx install/inject this is the case.

Richardk2n commented 2 years ago

I assume you are talking about "python -m mypy"? "python mypy" wont work i think? "python -m mypy" would?

sathlan commented 2 years ago

Hi,

so python mypy does work, basically the code as provided work in my env. I agree though that the exact mechanism that makes it work doesn't feel very robust:

~/.local/bin/pylsp -> ~/.local/pipx/venvs/python-lsp-server/bin/pylsp

cd ~/.local/pipx/venvs/python-lsp-server/bin && python mypy (cwd is set by pylsp)

which is equivalent to:

~/src/my-nice-python-project/venvs/bin/python ~/.local/pipx/venvs/python-lsp-server/bin/mypy ^^^ this is overrided by the venvs loading

At least that's how I understand it worked :), but it definitively worked in my env.

Don't have a ton of time to work on this, but happy to find a better way to achieve that.

Richardk2n commented 1 year ago

The feature set requested here is covered by the changes in #24 (as far as I am aware)