-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnj_config.py
137 lines (121 loc) · 5.14 KB
/
nj_config.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os
import re
import sys
import subprocess
import platform
def which(cmd):
return subprocess.Popen(["/usr/bin/which",cmd],stdout=subprocess.PIPE).communicate()[0].rstrip(os.linesep)
def julia_base_from_which_julia():
path = "";
which_julia = which("julia")
if len(which_julia) > 0:
real_path = os.path.realpath(which_julia)
if real_path:
dirname = os.path.dirname(real_path)
path = os.path.split(dirname)[0]
return path
def julia_base_from_where_julia():
path = "";
DEVNULL = open(os.devnull, 'w')
where_julia = subprocess.Popen(["where","julia.exe"],stdout=subprocess.PIPE,stderr=DEVNULL).communicate()[0];
if len(where_julia) > 0:
real_path = os.path.realpath(where_julia.rstrip(os.linesep))
if real_path:
dirname = os.path.dirname(real_path)
path = os.path.split(dirname)[0]
return path
def julia_base_from_home_directory():
home = os.path.expanduser("~")
julia_dir = os.path.join(home,"julia")
if os.path.isdir(julia_dir): return julia_dir
return "";
def julia_base_from_home_directory_win():
home = os.path.expanduser("~")
path = "";
search_folder = os.path.join(home, "AppData\Local")
DEVNULL = open(os.devnull, 'w')
if os.path.isdir(search_folder):
where_julia = subprocess.Popen(["where","julia.exe", "/r", search_folder],stdout=subprocess.PIPE,stderr=DEVNULL).communicate()[0];
#julia_dir,filename = os.path.split(where_julia)
real_path = os.path.realpath(where_julia.rstrip(os.linesep))
#if os.path.isdir(julia_dir): return julia_dir
if real_path:
dirname = os.path.dirname(real_path)
path = os.path.split(dirname)[0]
return path
def julia_base_from_applications():
julia_dir = "/Applications/Julia-0.3.0.app/Contents/Resources/julia/"
if os.path.isdir(julia_dir): return julia_dir
return ""
def find_julia_base(operating_system):
if operating_system == "win":
path = julia_base_from_where_julia()
if path == "": path = julia_base_from_home_directory_win()
else:
path = julia_base_from_which_julia()
if path == "": path = julia_base_from_home_directory()
if path == "" and len(sys.argv) > 1 and sys.argv[1] == "mac": path = julia_base_from_applications()
path = re.sub(" ",r"\ ",path)
return path
def node_version():
version = subprocess.Popen(["node","--version"],stdout=subprocess.PIPE).communicate()[0];
if len(version) > 0:
version = re.sub(r"^v([0-9]*\.[0-9]*\.)([0-9]*).*$","\g<1>x",version).rstrip(os.linesep)
return version
def get_nj_lib_define_variable():
path = os.path.abspath("lib")
return re.sub(r"\\","\\\\\\\\",path)
def julia_version(julia_path):
line = subprocess.Popen([julia_path,"-v"],stdout=subprocess.PIPE).communicate()[0].rstrip(os.linesep)
return re.sub(r".* ([0-9]\.[0-9])\.[0-9]+.*","\g<1>",line)
def get_julia_lib(operating_system):
if operating_system == "win": path = find_julia_base(operating_system) + "\\lib\\julia"
else:
which_julia = which("julia")
if len(which_julia) > 0 and (operating_system != "linux" or platform.linux_distribution()[0] != ""):
julia_path = os.path.realpath(which_julia)
version = julia_version(julia_path)
if version == "0.4" or version == "0.5":
path = subprocess.Popen([julia_path,"-e",'println(abspath(dirname(Libdl.dlpath("libjulia"))))'],stdout=subprocess.PIPE).communicate()[0].rstrip(os.linesep)
else:
path = re.sub(r"\\ "," ",find_julia_base(operating_system))
if path == "/usr":
if platform.linux_distribution()[0] == "centos": path = path + "/lib64/julia";
elif platform.linux_distribution()[0] == "Ubuntu": path = path + "/lib/x86_64-linux-gnu/julia"
else: path = path + "/lib/julia"
else: path = path + "/lib/julia"
else: path = re.sub(r"\\ "," ",find_julia_base(operating_system)) + "/lib/julia"
return path
def get_julia_lib_define_variable(operating_system):
path = get_julia_lib(operating_system)
return re.sub(r"\\","\\\\\\\\",path)
def get_gcc_version():
version = ""
which_gcc = which("gcc")
if len(which_gcc) > 0:
output = subprocess.Popen([which_gcc,"--version"],stdout=subprocess.PIPE).communicate()[0]
line = output.split("\n")[0]
version = re.sub(r"^gcc.*\) ([0-9]*\.[0-9]*)\.([0-9]*)$","\g<1>",line)
return version
def get_gcc_target():
version = ""
which_gcc = which("gcc")
if len(which_gcc) > 0:
output = subprocess.Popen([which_gcc,"-v"],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[1]
line = output.split("\n")[3]
target = line.split()[1]
return target
if sys.argv[2] == "version": print node_version()
elif sys.argv[2] == "base":
path = find_julia_base(sys.argv[1])
if not path == "": print path
elif sys.argv[2] == "nj_lib_define":
print get_nj_lib_define_variable()
elif sys.argv[2] == "julia_lib":
print get_julia_lib(sys.argv[1])
elif sys.argv[2] == "julia_lib_define":
print get_julia_lib_define_variable(sys.argv[1])
elif sys.argv[2] == "gcc_version":
print get_gcc_version()
elif sys.argv[2] == "gcc_target":
print get_gcc_target()