-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.py
49 lines (40 loc) · 1.97 KB
/
build.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
import os
import pathlib
import shutil
from distutils.command.build_ext import build_ext
from distutils.core import setup, Extension
libstable_module = Extension('libstable',
libraries=["blas", "gsl", "m", "gslcblas"],
sources=[
"./libstable/stable/src/mcculloch.c",
"./libstable/stable/src/methods.c",
"./libstable/stable/src/stable_cdf.c",
"./libstable/stable/src/stable_common.c",
"./libstable/stable/src/stable_dist.c",
"./libstable/stable/src/stable_fit.c",
"./libstable/stable/src/stable_integration.c",
"./libstable/stable/src/stable_koutrouvelis.c",
"./libstable/stable/src/stable_pdf.c",
"./libstable/stable/src/stable_q.c",
"./libstable/stable/src/stable_rnd.c"])
# SEE: https://github.com/python-poetry/poetry/issues/11
class ExtensionBuild(build_ext):
def run(self):
build_ext.run(self)
# Copy built extensions back to project
self.check_extensions_list(self.extensions)
for ext in self.extensions:
output = self.get_ext_fullpath(ext.name)
if not os.path.exists(output):
continue
relative_extension = os.path.relpath(output, self.build_lib)
file_extension = pathlib.Path(relative_extension).suffix
dest = os.path.join(
"./pystable/_extensions", # TODO: remove hard code
ext.name+file_extension
)
shutil.copyfile(output, dest)
mode = os.stat(dest).st_mode
mode |= (mode & 0o444) >> 2
os.chmod(dest, mode)
setup(ext_modules=[libstable_module], cmdclass=dict(build_ext=ExtensionBuild))