-
Notifications
You must be signed in to change notification settings - Fork 216
Add docs on Python interpreter/env considerations #643
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
base: develop
Are you sure you want to change the base?
Add docs on Python interpreter/env considerations #643
Conversation
#### Example: NeoVim | ||
|
||
For instance, if you use NeoVim's `vim.lsp` functions to set up the LSP configuration yourself, whether with your own config or a default one provided by [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig), you can set/override the command it uses to launch `pylsp` like so: | ||
|
||
```vim | ||
lua << EOF | ||
vim.lsp.config('pylsp', { | ||
-- Using the approach from Question 1, Option 4 to launch in an "overlay" venv | ||
-- on top of the project's venv, if any (NeoVim takes care of sharing LSP servers | ||
-- invocations between files in the same project): | ||
cmd = { 'uv', 'run', '--with', 'python-lsp-server,pylsp-mypy', 'pylsp' }, | ||
} | ||
EOF | ||
``` | ||
|
||
See [python-lsp-config#68 (comment)][issue-68-comment] for an example that doesn't use `uv` but tries to determine the project venv manually (e.g. for use with Question 1, Option 3). | ||
|
||
[issue-68-comment]: https://github.com/python-lsp/python-lsp-server/pull/68#issuecomment-894650876 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll probably ask me to remove this part because it's editor-specific.
Not sure if there is a better way to demonstrate how to apply some of the advice in this document in a real configuration (or whether that should be done at all).
|
||
### Option 2 (better but still bad): In a global virtualenv specifically for `python-lsp-server` or your editor | ||
|
||
This is better than the approach above, but won't help with plugins that need to run in your project's environment and don't have configuration variables to facilitate this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be improved. Maybe there should be single configuration option for environment path and iti should be passed to all plugins?
Currently jedi accepts pylsp.plugins.jedi.environmet
(and if needed also pylsp.plugins.jedi.extra_paths
). I think this should be mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be improved. Maybe there should be single configuration option for environment path and iti should be passed to all plugins?
Not all plugins would be able to respect this, or at least not fully - e.g. it wouldn't really help with Rope-based ones because you'd still have issues if your project's Python version doesn't match the one that pylsp
is running in, because Rope uses the standard library's ast
module to parse files, which is tied to that specific version.
Currently jedi accepts pylsp.plugins.jedi.environmet (and if needed also pylsp.plugins.jedi.extra_paths). I think this should be mentioned.
That the environment can be configured for Jedi-based plugins is mentioned in the plugin list near the start of the document. I didn't want to repeat the exact option names etc. to not make it needlessly long, but I did include a link to CONFIGURATION.md
as a footnote in such cases.
Fixes #642.