Neovim plugin that helps manage python requirements.
demo.mp4
- Integrated with
lspand provides completions - Uses
treesitterparser to readrequirements.txt, more robust than ad-hoc parsing - Displays diagnostics in
normalmode with warnings for not using latest version - Cache
pypiresponses within a session to improve performance - Auto upgrade dependencies when keymaps are configured
- Display package description from PyPI in a floating window with syntax highlighting
- Supports custom
index-urlandextra-index-urlfor finding packages
- neovim
>= 0.10.0 - treesitter parser:
- requirements:
For
requirements.txt - toml: For
pyproject.toml
- requirements:
For
- System dependencies:
curl: Used to call pypi API
{
'MeanderingProgrammer/py-requirements.nvim',
dependencies = { 'nvim-treesitter/nvim-treesitter' },
config = function()
require('py-requirements').setup({})
end,
}Below is the default configuration, any part of it can be modified.
require('py-requirements').setup({
-- Endpoint used for getting package versions
index_url = 'https://pypi.org/simple/',
-- Fallback endpoint in case 'index_url' fails to find a package
extra_index_url = nil,
-- Specify which file patterns plugin is active on
-- For info on patterns, see :h pattern
file_patterns = { '.*requirements.*.txt', '.*pyproject.*.toml' },
-- Options for how diagnostics are displayed
diagnostic_opts = { padding = 5 },
-- For available options, see :h vim.lsp.util.open_floating_preview
float_opts = { border = 'rounded' },
filter = {
-- Pull only final release versions, this will ignore alpha, beta,
-- release candidate, post release, and developmental release versions
final_release = false,
-- Ignore yanked package versions
yanked = true,
},
-- Enabled by default if you want to disable lsp completions set to false
enable_lsp = true,
})local py = require('py-requirements')
py.setup({...})
vim.keymap.set('n', '<leader>ru', py.upgrade, {})
vim.keymap.set('n', '<leader>rU', py.upgrade_all, {})
vim.keymap.set('n', '<leader>rK', py.show_description, {})On by default and the recommended way of getting version completions from this plugin. Requires no additional configuration, assuming you have general LSP completions. Works with any completion engine out of the box!
- Does not read or otherwise interact with
pip.conffile
- crates.nvim: Many ideas were taken from this project and translated to work with Python dependencies rather than Rust crates. I also used the in-process lsp implementation as an awesome reference lsp.lua.
- cmp-pypi: Found this one rather late, similar
idea but built to work with
pyproject.tomlfiles