Skip to content

Commit 9d38d2b

Browse files
committed
Make virtualenv.vim compatible with Python 3.
The `virtualenv.vim` file used the `execfile()` function to run the `activate_this.py` script from the active virtual environment. However, `execfile()` was removed in Python 3. This replaces the call to `execfile()` with a process that should be compatible with Python 2 and Python 3: 1. Read the script contents into a string. 2. Pass the string to `compile()` to get a compiled script object. 3. Pass the compiled script object to `exec()`.
1 parent a9afe07 commit 9d38d2b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

autoload/pymode/virtualenv.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ activate_this = os.path.join(os.path.join(ve_dir, 'bin'), 'activate_this.py')
2323
if not os.path.exists(activate_this):
2424
activate_this = os.path.join(os.path.join(ve_dir, 'Scripts'), 'activate_this.py')
2525

26-
execfile(activate_this, dict(__file__=activate_this))
26+
f = open(activate_this)
27+
try:
28+
source = f.read()
29+
finally:
30+
f.close()
31+
32+
exec(compile(source, activate_this, 'exec'), dict(__file__=activate_this))
2733
EOF
2834

2935
call pymode#WideMessage("Activate virtualenv: ".$VIRTUAL_ENV)

0 commit comments

Comments
 (0)