pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

[Feature] Add ability to set command to discover the interpreter

Open bmarroquin opened this issue 1 month ago • 1 comments

This would help in the situation where the IDE does not start the LSP with the Virtual Environment activated and where the virtual environment path is not fixed. See #1655

[tool.pyrefly]
# poetry interpreter path is different for all users, use info command instead
# python-interpreter-path=""C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\test-pyrefly-lsp-Pe66xNAj-py3.13\Scripts\python.exe""
python-interpreter-find-cmd = ["poetry", "env", "info", "-e"]

Alternatively, just specifying the tool that supports a run sub command could make this generic

[tool.pyrefly]
venv_manager  = "poetry | hatch | uv | pipenv"

interpreter = run([venv_manager, "run", "python", "-c", "import sys;print(sys.executable)"])

bmarroquin avatar Nov 22 '25 07:11 bmarroquin

Thanks for the suggestion! This seems like a great idea for the long tail of package managers that we probably can't fully support with baked-in heuristics and might not always use relative paths for their python interpreters (e.g. all the ones you listed, nix and guix, and I'm sure people are coming up with new ones)

I think it's at least possible you'd need the ability to run two commands in one shell - one to load up an environment and another to find the interpreter - for some use cases. In particular I think supporting a direnv-like setup where a shell hook sets a bunch of environment variables might be important - nix relies on PATH manipulation to load dependencies and I think that might not be terribly unusual

cc @connernilsen

stroxler avatar Nov 22 '25 16:11 stroxler