summaryrefslogtreecommitdiff
path: root/virtualenv_support/activate_this.py
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2009-10-21 05:21:40 +0200
committerJannis Leidel <jannis@leidel.info>2009-10-21 05:21:40 +0200
commit8aad93295cfbf73567bd4ba7411b67d62717693c (patch)
tree1f9705a61bcca10d68039f4abd35d0549d233123 /virtualenv_support/activate_this.py
parentfeeddc5d38b3c53c4b7b010600589b5b7f92b1db (diff)
downloadvirtualenv-8aad93295cfbf73567bd4ba7411b67d62717693c.tar.gz
Moved support-files in a package to get rid of the package_data hack and reliably distribute them
Diffstat (limited to 'virtualenv_support/activate_this.py')
-rw-r--r--virtualenv_support/activate_this.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/virtualenv_support/activate_this.py b/virtualenv_support/activate_this.py
new file mode 100644
index 0000000..b7aafe3
--- /dev/null
+++ b/virtualenv_support/activate_this.py
@@ -0,0 +1,29 @@
+"""By using execfile(this_file, dict(__file__=this_file)) you will
+activate this virtualenv environment.
+
+This can be used when you must use an existing Python interpreter, not
+the virtualenv bin/python
+"""
+
+try:
+ __file__
+except NameError:
+ raise AssertionError(
+ "You must run this like execfile('path/to/active_this.py', dict(__file__='path/to/activate_this.py'))")
+import sys
+import os
+
+base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
+prev_sys_path = list(sys.path)
+import site
+site.addsitedir(site_packages)
+sys.real_prefix = sys.prefix
+sys.prefix = base
+# Move the added items to the front of the path:
+new_sys_path = []
+for item in list(sys.path):
+ if item not in prev_sys_path:
+ new_sys_path.append(item)
+ sys.path.remove(item)
+sys.path[:0] = new_sys_path