comparison planemo/lib/python3.7/site-packages/virtualenv/activation/python/activate_this.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
1 # -*- coding: utf-8 -*-
2 """Activate virtualenv for current interpreter:
3
4 Use exec(open(this_file).read(), {'__file__': this_file}).
5
6 This can be used when you must use an existing Python interpreter, not the virtualenv bin/python.
7 """
8 import os
9 import site
10 import sys
11
12 try:
13 abs_file = os.path.abspath(__file__)
14 except NameError:
15 raise AssertionError("You must use exec(open(this_file).read(), {'__file__': this_file}))")
16
17 bin_dir = os.path.dirname(abs_file)
18 base = bin_dir[: -len("__BIN_NAME__") - 1] # strip away the bin part from the __file__, plus the path separator
19
20 # prepend bin to PATH (this file is inside the bin directory)
21 os.environ["PATH"] = os.pathsep.join([bin_dir] + os.environ.get("PATH", "").split(os.pathsep))
22 os.environ["VIRTUAL_ENV"] = base # virtual env is right above bin directory
23
24 # add the virtual environments libraries to the host python import mechanism
25 prev_length = len(sys.path)
26 for lib in "__LIB_FOLDERS__".split(os.pathsep):
27 path = os.path.realpath(os.path.join(bin_dir, lib))
28 site.addsitedir(path.decode("utf-8") if "__DECODE_PATH__" else path)
29 sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
30
31 sys.real_prefix = sys.prefix
32 sys.prefix = base