-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add support for detecting venvs from pipenv and poetry projects #40
Conversation
Thanks for the PR man. I've trying to sort this out and it's been driving me nuts, lol. I tried doing that with something along the lines of the following and I am still unable to get the packages from the venv loaded: (lsp-register-custom-settings
'(("python.venvPath" "/")
("python.venv" (lambda () (file-relative-name (or (lsp-pyright-locate-venv) (poetry-get-virtualenv)) "/"))))))) |
Thanks for looking at the PR! So, if I understand you correctly, pyright isn't loading packages from the project venv when you use the current code? Which platform are you on? I think the python.venv setting overrides the load paths that pyright gets from |
yes, it doesn't load the packages from the project env. I am not sure if this is the correct way to test this, but I am checking this by running Looking at the pyright implementation itself: if (configOptions.venvPath !== undefined && configOptions.venv) {
.
.
.
const sitePackagesPath = findSitePackagesPath(fs, combinePaths(venvPath, libPath), importFailureInfo); I thought pyright looks for the site-packge when both |
It'd also be good to look at the I think in general the way lsp-pyright finds the venv and python should be rethought a bit, since right now it silently assumes a default that's unlikely to be correct for most people. |
Hi, is this PR stale? I really need this feature. |
I created a PR to allow us to more easily configure how we choose the |
Please don't complicate virtualenv discovery in this project, just keep it simple with defcustoms as they currently are so people can customize them in the mode hooks or use emacs-pet. |
I agree that emacs-pet is the canonical solution to this problem and I'm closing this PR now. Thanks for drawing my attention to that project. Adding an example showing how to integrate emacs-pet with lsp-pyright would make sense as using project tools to manage python venvs is a prevalent scenario and lsp-pyright is basically useless OOTB in these cases right now. |
This PR adds support for detecting if a project is managed using either poetry or pipenv and configuring pyright to use the venv and python interpreter created by those tools.
I have been using this code for a while without problems and I think it's extremely useful. However, there are a couple of problems with the code, thus the WIP tag:
pipenv
project ifPipfile
exists in the project root andpipenv
is found inPATH
. Likewise, poetry is assumed ifpyproject.toml
is found in the project root andpoetry
is found inPATH
. This naive approach misses several obvious cases, but I wonder if there is a method or even need to make the detection mechanism more accurate or if it's better to add a customization variable that overrides the detection?I'm looking forward to your feedback!