Skip to content

Commit 6e86135

Browse files
committed
Activate virtualenv manually.
1 parent bffee43 commit 6e86135

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

Changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Changelog
3333
* Options added:
3434
'pymode_rope_regenerate_on_write', 'pymode_rope_completion', 'pymode_rope_complete_on_dot'
3535

36+
* Commands added:
37+
'PymodeVirtualenv'
38+
3639
* Commands changed:
3740
'PyDoc' -> 'PymodeDoc'
3841
'Pyrun' -> 'PymodeRun'

autoload/pymode/virtualenv.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ fun! pymode#virtualenv#init() "{{{
1010
PymodePython enable_virtualenv()
1111

1212
endfunction "}}}
13+
14+
fun! pymode#virtualenv#activate(relpath) "{{{
15+
let g:pymode_virtualenv_path = getcwd() . '/' . a:relpath
16+
call pymode#virtualenv#init()
17+
endfunction "}}}

doc/pymode.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ Bind keys to show documentation for current word (selection)
202202
2.6 Support virtualenv ~
203203
*pymode-virtualenv*
204204

205-
Enable virtualenv detection *'g:pymode_virtualenv'*
205+
Commands:
206+
*:PymodeVirtualenv* <path> -- Activate virtualenv (path is related to
207+
current working directory)
208+
209+
Enable automatic virtualenv detection *'g:pymode_virtualenv'*
206210
>
207211
let g:pymode_virtualenv = 1
208212

ftplugin/python/pymode.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ if !pymode#default('g:pymode_init', 1)
99
call pymode#breakpoint#init()
1010
endif
1111

12+
command! -buffer -nargs=1 PymodeVirtualenv call pymode#virtualenv#activate(<args>)
13+
1214
" Setup events for pymode
1315
au pymode BufWritePre <buffer> call pymode#buffer_pre_write()
1416
au pymode BufWritePost <buffer> call pymode#buffer_post_write()

pymode/virtualenv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import os.path
44
import vim # noqa
55

6-
from .utils import pymode_message
6+
from .utils import pymode_message, catch_and_print_exceptions
77

88

9+
@catch_and_print_exceptions
910
def enable_virtualenv():
1011
""" Enable virtualenv for vim.
1112
@@ -16,6 +17,7 @@ def enable_virtualenv():
1617
path = vim.eval('g:pymode_virtualenv_path')
1718
enabled = vim.eval('g:pymode_virtualenv_enabled')
1819
if path == enabled:
20+
pymode_message('Virtualenv %s already enabled.' % path)
1921
return False
2022

2123
activate_this = os.path.join(os.path.join(path, 'bin'), 'activate_this.py')

0 commit comments

Comments
 (0)