Giter Site home page Giter Site logo

rafi / vim-venom Goto Github PK

View Code? Open in Web Editor NEW
32.0 3.0 7.0 12 KB

Select Python runtimes or activate virtual-environments while working in Neo/Vim.

Python 6.93% Lua 42.03% Vim Script 51.04%
vim neovim python virtual-environment virtualenv activate runtime plugin

vim-venom's Introduction

Vim Venom

⚠️ DEPRECATED! ⚠️ 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.

  • Select python runtime for current project
  • Detect pyenv and virtualenvwrapper placeholders (.venv and .python-version)
  • Detect virtualenv via popular tools: pipenv, poetry, etc.
  • User Vim events on de/activation
  • Optional Lua light-weight version

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

⚠️ DEPRECATED! ⚠️ 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:

  • require('venom').activate()
  • require('venom').deactivate()
  • require('venom').statusline()

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

  • :VenomActivate [path] / venom#activate([path])
    • Without argument: Try to detect virtual-environment
    • With argument: Find python runtime in path and place a marker to persist selection.
  • :VenomDeactivate / venom#deactivate()
  • venom#statusline()

Python Runtime Selection

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

⚠️ 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:

  • VenomActivated
  • VenomDeactivated

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

  • By default, FileType python event triggers plugin activation. You can add other events yourself, e.g.: autocmd BufWinEnter *.py call venom#activate()
  • Plugin doesn't alter Neovim's g:python3_host_prog. I don't think it should.
  • Mostly tested with Neovim

Copyright

© 2019-2022 Rafael Bodill

vim-venom's People

Contributors

rafi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vim-venom's Issues

Venom gets loaded after native lsp client

I am using the vim version of vim-venom.

I need to restart the native lsp client, to get an environment working. This issue does not exist when I start nvim from a terminal, where the environment is already activated. My guess is that the lsp client gets initiated before, venom activates the environment.

Requires python3 host modules installed in virtual environment

I'm not sure I understand correctly what this plugin is supposed to do but I'm having trouble using NeoVim with modified $PATH. How is this supposed to work exactly?

I have python3 provider (neovim python module) and e.g. pylint installed globally. When I install this plugin and open NeoVim it automatically activates detected virtual environment but stops detecting both neovim and pylint modules so many NeoVim plugins stop working. The only way to make it work is to install these modules inside the virtual environment which beats the purpose of isolation in the first place.

I'd imagine this plugin exists exactly to solve this issue i.e. to let NeoVim keep the host's $PATH and only overwrite it for shells spawned by :! and :terminal. This way one could run NeoVim and use it as it was in global context, with all the dependencies, plugins and python modules loaded from the host, while running all the shell commands in the virtual environment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.