Mercurial > repos > guerler > hhblits
comparison bin/activate_this.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
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") - 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/python3.8/site-packages".split(os.pathsep): | |
27 path = os.path.realpath(os.path.join(bin_dir, lib)) | |
28 site.addsitedir(path.decode("utf-8") if "" 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 |