Statistics
| Branch: | Revision:

root / env / bin / activate_this.py @ 1a305335

History | View | Annotate | Download (1005 Bytes)

1
"""By using execfile(this_file, dict(__file__=this_file)) you will
2
activate this virtualenv environment.
3

4
This can be used when you must use an existing Python interpreter, not
5
the virtualenv bin/python
6
"""
7

    
8
try:
9
    __file__
10
except NameError:
11
    raise AssertionError(
12
        "You must run this like execfile('path/to/activate_this.py', dict(__file__='path/to/activate_this.py'))")
13
import sys
14
import os
15

    
16
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17
if sys.platform == 'win32':
18
    site_packages = os.path.join(base, 'Lib', 'site-packages')
19
else:
20
    site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
21
prev_sys_path = list(sys.path)
22
import site
23
site.addsitedir(site_packages)
24
sys.real_prefix = sys.prefix
25
sys.prefix = base
26
# Move the added items to the front of the path:
27
new_sys_path = []
28
for item in list(sys.path):
29
    if item not in prev_sys_path:
30
        new_sys_path.append(item)
31
        sys.path.remove(item)
32
sys.path[:0] = new_sys_path