python-lsp/python-lsp-ruff

Virtual environment not respected with `pipx`

jhossbach opened this issue · 0 comments

I'm not sure how reproducible this will be on other environments (although it might not be too hard to replicate with a Dockerfile, especially if there's a pipx - ready image), but currently I'm running into this (on MacOS, fwiw), after

pipx install --force "ruff>=0.1"

And it goes away after

pipx install --force "ruff<0.1"

Some info about versions:

$ pipx list | rg 'ruff|lsp'
   package python-lsp-server 1.8.2, installed using Python 3.11.6
    - pylsp
   package ruff 0.0.292, installed using Python 3.11.6
    - ruff
$ pipx runpip python-lsp-server freeze | rg ruff
python-lsp-ruff==1.5.2
ruff==0.1.0

Based on the above, even though I've got the incompatible ruff version in my python-lsp-server environment, I can avoid this issue if ruff --version is compatible. Conversely (?), if I had a good version range in the python-lsp-server venv, it wouldn't matter if my globally-installed ruff had breaking changes.

change to sys.executable

Limited testing with my pipx environments:

at 10:12:30 🍎 ❯ ~/.local/pipx/venvs/python-lsp-server/bin/python -c 'import sys; import os; os.system(sys.executable + " -m ruff --version")'
ruff 0.1.0

at 10:12:54 🍎 ❯ ~/.local/pipx/venvs/ruff/bin/python -c 'import sys; import os; os.system(sys.executable + " -m ruff --version")'
ruff 0.0.292

I'd hope that testing in a CPython python -m venv environment would be sufficient, but it's possible that different python distributions (e.g. circuitpython) or project tools (pdm, poetry, etc.) might behave differently.

Based on personal anecdotal evidence, I haven't run into issues with using sys.executable like this in the past, but there are a lot of environments I haven't worked in yet (embedded, WASM, etc.)

Originally posted by @znd4 in #49 (comment)