SEESenv/bin/activate_this.py
author amit@thunder
Mon, 12 Apr 2010 15:12:41 +0530
changeset 49 3b5f1341d6c6
parent 3 6cee07c589cb
permissions -rw-r--r--
Some small changes ... bug fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     1
"""By using execfile(this_file, dict(__file__=this_file)) you will
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     2
activate this virtualenv environment.
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     3
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     4
This can be used when you must use an existing Python interpreter, not
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     5
the virtualenv bin/python
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     6
"""
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     7
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     8
try:
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
     9
    __file__
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    10
except NameError:
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    11
    raise AssertionError(
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    12
        "You must run this like execfile('path/to/active_this.py', dict(__file__='path/to/activate_this.py'))")
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    13
import sys
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    14
import os
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    15
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    16
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    17
site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    18
prev_sys_path = list(sys.path)
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    19
import site
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    20
site.addsitedir(site_packages)
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    21
sys.real_prefix = sys.prefix
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    22
sys.prefix = base
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    23
# Move the added items to the front of the path:
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    24
new_sys_path = []
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    25
for item in list(sys.path):
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    26
    if item not in prev_sys_path:
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    27
        new_sys_path.append(item)
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    28
        sys.path.remove(item)
6cee07c589cb Changes in path of some of the files ...
amit@thunder
parents:
diff changeset
    29
sys.path[:0] = new_sys_path