forked from python-mode/python-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtualenv.py
More file actions
37 lines (28 loc) · 978 Bytes
/
virtualenv.py
File metadata and controls
37 lines (28 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
""" Support virtualenv in pymode. """
import os.path
from .environment import env
@env.catch_exceptions
def enable_virtualenv():
""" Enable virtualenv for vim.
:return bool:
"""
path = env.var('g:pymode_virtualenv_path')
enabled = env.var('g:pymode_virtualenv_enabled')
if path == enabled:
env.message('Virtualenv %s already enabled.' % path)
return env.stop()
activate_this = os.path.join(os.path.join(path, 'bin'), 'activate_this.py')
# Fix for windows
if not os.path.exists(activate_this):
activate_this = os.path.join(
os.path.join(path, 'Scripts'), 'activate_this.py')
f = open(activate_this)
try:
source = f.read()
exec(compile( # noqa
source, activate_this, 'exec'), dict(__file__=activate_this))
env.message('Activate virtualenv: ' + path)
env.let('g:pymode_virtualenv_enabled', path)
return True
finally:
f.close()