-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetup.py
92 lines (74 loc) · 2.41 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ==================================
# File Name: setup.py
# Author: En-Kun Li, Han Wang
# Mail: [email protected], [email protected]
# Created Time: 2023-09-06 19:43:34
# ==================================
import numpy as np
from setuptools import find_packages
from Cython.Build import cythonize
from distutils.core import setup, Extension
import sys
argv_replace = []
gsl_prefix = '/usr'
for arg in sys.argv:
if arg.startswith('--with-gsl='):
gsl_prefix = arg.split('=', 1)[1]
else:
argv_replace.append(arg)
sys.argv = argv_replace
lib_gsl_dir = gsl_prefix+"/lib"
include_gsl_dir = gsl_prefix+"/include"
# Update these paths accordingly
# extensions
code_lib = 'gwspace'
def func_ext(name, src):
return Extension(
code_lib+"."+name,
sources=src,
include_dirs=["include",
include_gsl_dir, np.get_include()],
extra_compile_args=["-std=c99", "-O3"],
libraries=['gsl', 'gslcblas', 'm'],
library_dirs=[lib_gsl_dir],
)
fastgb_ext = func_ext("libFastGB", # name of the lib
src=[
"src/FastGB.pyx",
"src/spacecrafts.c",
"src/GB.c",
])
imrphd_ext = func_ext('pyIMRPhenomD',
src=[
'src/pyIMRPhenomD.pyx',
'src/IMRPhenomD.c',
'src/IMRPhenomD_internals.c',
])
# add all extensions
extensions = []
extensions.append(fastgb_ext)
extensions.append(imrphd_ext)
# translate the constants.h to constants.py
fp_const_h = "./include/constants.h"
fp_const_py = "./gwspace/constants.py"
with open(fp_const_h, "r") as fp_in:
with open(fp_const_py, "w") as fp_out:
lines = fp_in.readlines()
for line in lines:
if (len(line.split())) >= 3:
if line.split()[0] == "#define":
try:
_ = float(line.split()[2])
string_out = line.split()[1] + " = " + line.split()[2] + "\n"
fp_out.write(string_out)
except ValueError as e:
continue
setup(
name='gwspace',
version='0.0.1',
ext_modules=cythonize(extensions),
author='En-Kun Li, Han Wang',
packages=find_packages(),
)