-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup_developer.py
211 lines (171 loc) · 6.48 KB
/
setup_developer.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import os
from os import listdir
from os.path import isfile, join
import shutil
from distutils.core import setup
from setuptools.command.build_ext import build_ext
import numpy
from Cython.Build import cythonize
import subprocess as sb
from isp import ROOT_DIR
cy_path = os.path.join(ROOT_DIR, 'cython_code')
def exc_cmd(cmd, **kwargs):
"""
Execute a subprocess Popen and catch except.
:param cmd: The command to be execute.
:param kwargs: All subprocess.Popen(..).
:return: The stdout.
:except excepts: SubprocessError, CalledProcessError
:keyword stdin: Default=subprocess.PIPE
:keyword stdout: Default=subprocess.PIPE
:keyword stderr: Default=subprocess.PIPE
:keyword encoding: Default=utf-8
"""
stdout = kwargs.pop("stdout", sb.PIPE)
stdin = kwargs.pop("stdin", sb.PIPE)
stderr = kwargs.pop("stderr", sb.PIPE)
encoding = kwargs.pop("encoding", "utf-8")
with sb.Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr, encoding=encoding, **kwargs) as p:
try:
std_out, std_err = p.communicate(timeout=15)
except sb.TimeoutExpired:
p.kill()
std_out, std_err = p.communicate() # try again if timeout fails.
if p.returncode != 0: # Bad error.
raise sb.CalledProcessError(p.returncode, std_err.strip())
elif len(std_err) != 0: # Some possible errors trowed by the running subprocess, but not critical.
raise sb.SubprocessError(std_err.strip())
return std_out.strip()
def extract_nll():
try:
folder_nll = os.path.join(ROOT_DIR,"NLL7")
if os.path.isdir(folder_nll):
shutil.rmtree(folder_nll)
except:
pass
extract_at = os.path.join(ROOT_DIR, "NLL7")
try:
if not os.path.isdir(extract_at):
os.mkdir(extract_at)
else:
shutil.rmtree(extract_at)
os.mkdir(extract_at)
shutil.unpack_archive("NLL2023_src.tgz", extract_at)
os.mkdir(os.path.join(extract_at, "bin"))
except IOError as error:
print("Warnning", error)
return extract_at
def extract_focmec():
try:
folder_focmec = os.path.join(ROOT_DIR,"focmec")
if os.path.isdir(folder_focmec):
shutil.rmtree(folder_focmec)
except:
pass
check_focmec = os.path.join(ROOT_DIR, "focmec")
try:
if not os.path.isdir(check_focmec):
shutil.unpack_archive("focmec2023_src.tgz", ROOT_DIR)
else:
shutil.rmtree(check_focmec)
shutil.unpack_archive("focmec2023_src.tgz", ROOT_DIR)
except IOError as error:
print(error)
return check_focmec
def extract_mti():
try:
folder_mti = os.path.join(ROOT_DIR, "mti","green_source")
if os.path.isdir(folder_mti):
shutil.rmtree(folder_mti)
except:
pass
try:
folder_work_mti = os.path.join(ROOT_DIR, "mti","green")
if os.path.isdir(older_work_mti):
shutil.rmtree(older_work_mti)
except:
pass
extract_at = os.path.join(ROOT_DIR, "mti")
try:
if not os.path.isdir(extract_at):
os.mkdir(extract_at)
shutil.unpack_archive("isola2023_src.tgz", extract_at)
else:
shutil.unpack_archive("isola2023_src.tgz", extract_at)
if not os.path.isdir(folder_work_mti):
os.mkdir(folder_work_mti)
except IOError as error:
print(error)
return extract_at
class CustomBuildExtCommand(build_ext):
def run(self):
print("Extracting files")
nll_dir = extract_nll()
focmec_dir = extract_focmec()
mti_dir = extract_mti()
print("Finished extraction")
print("Start compiling")
self.make_nll(nll_dir)
self.make_focmec(focmec_dir)
self.make_mti(mti_dir)
print("Finished Compilation")
# run build
build_ext.run(self)
def make_nll(self, nll_dir):
src_path = os.path.join(nll_dir, "src")
bin_path = os.path.join(nll_dir, "bin")
command = "export MYBIN={bin_path}; cd {src_path}; sh compile_nll.sh".format(bin_path=bin_path, src_path=src_path)
try:
exc_cmd(command, shell=True)
print("NLL7 successfully installed")
except sb.CalledProcessError as e: # this is a bad error/warning.
print("Warnning on trying to run nll make file / NLL7 successfully installed")
print(e)
except sb.SubprocessError: # some warnings nothing so bad.
print("NLL7 successfully installed")
def make_focmec(self, focmec_dir):
src_path = os.path.join(focmec_dir, "src")
command = "sh build_package_sh"
try:
exc_cmd(command, cwd=src_path, shell=True)
print("FOCMEC successfully installed")
except sb.CalledProcessError as e: # this is a bad error.
print("Error on trying to run focmec make file.")
print(e)
except sb.SubprocessError: # some warnings nothing so bad.
print("FOCMEC successfully installed")
def make_mti(self, mti_dir):
green_path = os.path.join(mti_dir,"green_source")
work_dir = os.path.join(mti_dir,"green")
command = "sh compile_mti_ifort.sh"
try:
exc_cmd(command, cwd=green_path, shell=True)
print("MTI successfully installed")
self.copy_mti_binaries(green_path, work_dir)
except sb.CalledProcessError as e: # this is a bad error.
print("Error on trying to run MTI make file.")
print(e)
except sb.SubprocessError: # some warnings nothing so bad.
print("MTI successfully installed")
def copy_mti_binaries(self, source_code, destination):
allfiles = [f for f in listdir(source_code) if isfile(join(source_code, f))]
# iterate on all files to move them to destination folder
for f in allfiles:
src_path = os.path.join(source_code, f)
dst_path = os.path.join(destination, f)
shutil.copy(src_path, dst_path)
setup(
cmdclass={'build_ext': CustomBuildExtCommand,},
name='isp_package',
version='2.0',
description='ISP setup script',
packages=find_packages(include=['isp', 'isp.*']),
include_dirs=[numpy.get_include()])
#setup(
# cmdclass={
# 'build_ext': CustomBuildExtCommand,
# },
# ext_modules=cythonize(os.path.join(cy_path, 'ccwt_cy.pyx')),
# include_dirs=[numpy.get_include()],
# ext_package='isp.c_lib'
#)