forked from OSU-Net/cyder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivate.py
59 lines (42 loc) · 1.46 KB
/
activate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from glob import glob
import inspect
import os
import subprocess
import sys
from os import environ, path
def cy_path(x):
return path.join(ROOT, x)
def cy_addsitedir(x):
"""Do essentially what site.addsitedir does, except prepend the paths
Note: Import lines aren't supported, because they're not useful to us.
"""
if not path.exists(x):
return
for pth_name in glob(path.join(x, '*.pth')):
ps = []
with open(pth_name) as pth:
for line in pth:
line = line.strip()
if line[0] == '#':
continue
p = path.join(x, line)
if path.exists(p) and p not in sys.path:
ps.append(p)
sys.path[1:1] = ps
if x not in sys.path:
sys.path.insert(1, x)
def activate():
environ.setdefault('DJANGO_SETTINGS_MODULE', 'cyder.settings')
activator = cy_path('.env/bin/activate_this.py')
try:
execfile(activator, {'__file__': activator})
except:
pass
cy_addsitedir(cy_path('vendor')) # global (upstream) vendor library
cy_addsitedir(cy_path('vendor-local')) # local (project) vendor library
import cyder.signal_handlers # register the handlers
ROOT = path.dirname(path.abspath(inspect.stack()[0][1]))
if ROOT not in sys.path:
sys.path.insert(1, ROOT)
CYDER_REVISION = subprocess.check_output(
['git', '--git-dir=' + cy_path('.git'), 'rev-parse', 'HEAD']).rstrip()