-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
189 lines (117 loc) · 3.88 KB
/
setup.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python
"""
$Id: setup.py 894 2015-06-07 03:24:33Z weegreenblobbie $
A wrapper around setup_builder.py to provide the standard Python distutils
interface that everyone is familiar with.
This script invokes the scons build system to generate a SWIG interface file
and generate setup_build.py which does the actual distutils work of building
the Python module.
"""
import os
import sys
import subprocess
import shlex
import distutils.spawn
import os.path
#------------------------------------------------------------------------------
# Globals & constats
NSOUND_DIR = os.path.dirname(os.path.abspath(__file__))
SETUP_BUILDER_PY = "setup_builder.py"
NSOUND_H = os.path.join(NSOUND_DIR, "src", "Nsound", "Nsound.h")
def main():
tool_check()
configure()
process_nsound_h()
# execute actual distutils setup() script
import setup_builder
def is_exe(fpath):
'''
Return True if the shell can execute fpath.
'''
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
def which(program):
'''
Returns the full path to program if found, None otherwise.
Unlike other solutions, this finds .bat and .exe files also.
Reference: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
'''
extentions = ['', '.bat', '.exe']
for ext in extentions:
tool = program + ext
for path in os.environ['PATH'].split(os.pathsep):
exe = os.path.join(path, tool)
if is_exe(exe):
return exe
return None
def tool_check():
stdout = sys.stdout
tools = ['scons', 'swig']
for t in tools:
stdout.write("Checking for %s ..." % t)
tool = which(t)
if tool:
print(" %s" % tool)
else:
raise RuntimeError(
"FAILURE!\nCould not find tool '%s',"
" is it installed? Is it in your PATH?" % t)
def configure():
stdout = sys.stdout
#--------------------------------------------------------------------------
# Configure the Nsound python module by generating setup_builder.py
stdout.write("Configuring Nsound ...")
stdout.flush()
os.chdir(NSOUND_DIR)
cmd = ["scons", SETUP_BUILDER_PY]
subprocess.check_call(cmd)
print(" done")
def process_nsound_h():
'''
Read in Nsound.h and display configuration summay.
'''
d = {
'ao' : 'no',
'c++11' : 'no',
'cuda' : 'no',
'float64' : 'no',
'little-endian' : 'no',
'matplotlib' : 'no',
'openmp' : 'no',
'portaudio' : 'no',
'real-time-audio' : 'no',
}
release = None
with open(NSOUND_H, "r") as fd:
text = fd.readlines()
for l in text:
if '#define NSOUND_LIBAO 1' in l:
d['ao'] = 'yes'
elif '#define NSOUND_CPP11 1' in l:
d['c++11'] = 'yes'
elif '#define NSOUND_CUDA 1' in l:
d['cuda'] = 'yes'
elif '#define NSOUND_64_BIT 1' in l:
d['float64'] = 'yes'
elif '#define NSOUND_LITTLE_ENDIAN' in l:
d['little-endian'] = 'yes'
elif '#define NSOUND_C_PYLAB 1' in l:
d['matplotlib'] = 'yes'
elif '#define NSOUND_OPENMP 1' in l:
d['openmp'] = 'yes'
elif '#define NSOUND_LIBPORTAUDIO 1' in l:
d['portaudio'] = 'yes'
elif '#define PACKAGE_RELEASE' in l:
release = l.strip().split()[-1]
release = release.replace('"', '')
if d['c++11'] == 'yes' and d['portaudio'] == 'yes':
d['real-time-audio'] = 'yes'
#--------------------------------------------------------------------------
# Display summary
fmt = " %-16s: %s"
print( fmt % ('release', release))
keys = d.keys()
sorted(keys)
for k in keys:
print(fmt % (k, d[k]))
if __name__ == "__main__": main()
# :mode=python: