rafi / vim-venom

Select Python runtimes or activate virtual-environments while working in Neo/Vim.
32 stars 7 forks source link
activate neovim plugin python runtime vim virtual-environment virtualenv

Vim Venom

:warning: DEPRECATED! :warning: This plugin is no-longer maintained.

Please see github.com/rafi/neoconf-venom.nvim for a Neovim plugin that properly sets LSP servers' settings.

If you are not using Neovim, this might still work for you.

Features

Activates your Python virtual-environments while working in Neo/Vim.

Vim Version

If you choose to use the vim plugin, ensure your neo/vim instance supports python3, i.e. :echo has('python3') should print 1. Use your favorite plugin-manager, for example dein.vim:

call dein#add('rafi/vim-venom', { 'on_ft': 'python' })

Or, if you're using vim-plug, I got your back too:

Plug 'rafi/vim-venom', { 'for': 'python' }

You can change the default configuration:

Variable Description Default
g:venom_auto_activate Automatically tries to detect and activate virtualenv 1
g:venom_use_tools Use external-tools to detect virtualenv 1
g:venom_echo Upon activation show friendly message 1
g:venom_quiet Be quiet when failing to find environments 0
g:venom_symbol Icon for statusline helper function 🐍
g:venom_tools External-tools configuration See here

Lua Version

:warning: DEPRECATED! :warning: This plugin is no-longer maintained.

Please see github.com/rafi/neoconf-venom.nvim for a Neovim plugin that properly sets LSP servers' settings.

If you choose to use the Lua version, disable vim-plugin before loading the plugin, and once loaded, run setup:

vim.g.venom_loaded = 1     -- Before plugin loaded
require('venom').setup()   -- After plugin loaded

However, the current implement does not support tools (poetry, pipenv) and Vim commands and events.

The Lua API:

packer.nvim install example:

vim.g.venom_loaded = 1

use {
  'rafi/vim-venom',
  ft = {'python'},
  config = 'require("venom").setup()'
}

dein.vim install example:

call dein#add('rafi/vim-venom', {
  \ 'on_ft': 'python',
  \ 'hook_add': 'let g:venom_loaded = 1',
  \ 'hook_post_source': 'lua require("venom").setup()'
  \ })

You can change the default configuration:

require('venom').setup({
  auto_activate = true,
  echo = true,
  quiet = false,
  symbol = '🐍',
  root_patterns = {'.venv', '.python-version'},
  use_tools = true,
  tools = {},
})

Functions & Commands

Python Runtime Selection

User can activate a different Python runtime, and use auto-completion when selecting one, using :VenomActivate and Tab.

:warning: Only tested with Neovim.

Virtual-Environment Detection

Once activation runs manually (without arguments) or automatically when g:venom_auto_activate is enabled, plugin will attempt to detect the project's virtual-environment path using several strategies:

  1. Detect .venv/ directory in project's directory.
  2. Detect .venv file containing environment path in plain-text.
  3. Detect with external-tools (if g:venom_use_tools is enabled).

See the following g:venom_tools for external tools usage & support.

External Tools Integration

Enabling g:venom_use_tools leverages external tools in-order to resolve the project's virtual-environment path, plugin now supports:

You can extend and change the usage. These are the default values:

let g:venom_use_tools = 1
let g:venom_tools = {
  \ 'poetry': 'poetry env info -p',
  \ 'pipenv': 'pipenv --venv'
  \ }

User Events

As a user, you have two events you can hook triggers to extend behavior:

For example, if you use deoplete and deoplete-jedi together:

" Deoplete Jedi: Set python executable from PATH
autocmd User VenomActivated,VenomDeactivated
  \ let g:deoplete#sources#jedi#python_path =
  \   exepath('python' . (has('win32') ? '.exe' : ''))

Or use jedi-vim's new :JediUseEnvironment feature (pending #836):

" Jedi: Set environment from PATH
autocmd User VenomActivated,VenomDeactivated
  \ silent! execute 'JediUseEnvironment ' .
  \   exepath('python' . (has('win32') ? '.exe' : ''))

Caveats

Copyright

© 2019-2022 Rafael Bodill