-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsetup.py
225 lines (182 loc) · 6.16 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import setuptools
import setuptools.command.install
import setuptools.command.build_py
import setuptools.command.develop
import subprocess
import os
version = open('cosmosis/version.py').read().split('=')[1].strip().strip("'")
f90_mods = [
"datablock/cosmosis_section_names.mod",
"datablock/cosmosis_types.mod",
"datablock/cosmosis_wrappers.mod",
"datablock/cosmosis_modules.mod",
]
scripts = [
'bin/cosmosis',
'bin/cosmosis-campaign',
'bin/cosmosis-configure',
'bin/cosmosis-extract',
'bin/cosmosis-sample-fisher',
'bin/cosmosis-postprocess',
]
c_headers = [
"datablock/c_datablock.h",
"datablock/datablock_logging.h",
"datablock/datablock_types.h",
"datablock/cosmosis_constants.h",
"datablock/datablock_status.h",
"datablock/section_names.h",
]
cc_headers = [
"datablock/clamp.hh",
"datablock/entry.hh",
"datablock/fakearray.hh",
"datablock/ndarray.hh",
"datablock/datablock.hh",
"datablock/exceptions.hh",
"datablock/mdarraygen.hh",
"datablock/section.hh"
]
datablock_libs = ["datablock/libcosmosis.so"]
sampler_libs = ["samplers/multinest/multinest_src/libnest3.so",
"samplers/multinest/multinest_src/libnest3_mpi.so",
"samplers/polychord/polychord_src/libchord.so",
"samplers/polychord/polychord_src/libchord_mpi.so",
"samplers/minuit/minuit_wrapper.so"]
testing_files = [
"test/libtest/c_datablock_complex_array_test.c",
"test/libtest/c_datablock_double_array_test.c",
"test/libtest/c_datablock_int_array_test.c",
"test/libtest/c_datablock_multidim_complex_array_test.c",
"test/libtest/c_datablock_multidim_double_array_test.c",
"test/libtest/c_datablock_multidim_int_array_test.c",
"test/libtest/c_datablock_test.c",
"test/libtest/cosmosis_test.F90",
"test/libtest/cosmosis_tests.supp",
"test/libtest/datablock_test.cc",
"test/libtest/entry_test.cc",
"test/libtest/ndarray_test.cc",
"test/libtest/section_test.cc",
"test/libtest/test_c_datablock_scalars.h",
"test/libtest/test_c_datablock_scalars.template",
"test/libtest/Makefile",
"test/campaign.yml",
"test/included.yml",
"test/bad-campaign.yml",
"test/example-priors.ini",
"test/example-values.ini",
"test/example.ini",
]
other_files = ["postprocessing/latex.ini"]
compilers_config = ["config/compilers.mk", "config/subdirs.mk"]
def get_COSMOSIS_SRC_DIR():
cosmosis_src_dir = os.path.join(os.getcwd(), "cosmosis")
return cosmosis_src_dir
def make_cosmosis():
print("Running CosmoSIS main library compile command")
cosmosis_src_dir = get_COSMOSIS_SRC_DIR()
env = os.environ.copy()
env["COSMOSIS_SRC_DIR"] = cosmosis_src_dir
# If we are in a conda build env then the appropriate
# variable is called PREFIX. Otherwise if we are on
# a user's build env then it is called CONDA_PREFIX
if os.environ.get("CONDA_BUILD", "0") == "1":
prefix_name = "PREFIX"
conda_build = True
else:
prefix_name = "CONDA_PREFIX"
conda_build = False
conda = env.get(prefix_name)
if conda:
# User can switch on COSMOSIS_OMP manually, but it should
# always be on for conda.
env["COSMOSIS_OMP"] = "1"
# We also need Lapack to build some of the samplers
env["LAPACK_LINK"] = f"-L{conda}/lib -llapack"
# and minuit for that sampler
env['MINUIT2_LIB'] = f"{conda}/lib"
env['MINUIT2_INC'] = f"{conda}/include/Minuit2"
if conda_build:
env["COSMOSIS_ALT_COMPILERS"] = "1"
env['USER_FFLAGS'] = env['FFLAGS']
env['USER_CFLAGS'] = env['CFLAGS']
env['USER_CXXFLAGS'] = env['CXXFLAGS']
# and the MPI compiler
env["MPIFC"] = "mpif90"
env['FC'] = env.get('FC', 'gfortran')
subprocess.check_call(["make"], env=env, cwd="cosmosis")
class build_cosmosis(setuptools.Command):
description = "Build CosmoSIS and do nothing else"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
make_cosmosis()
class build_py_cosmosis(setuptools.command.build_py.build_py):
def run(self):
make_cosmosis()
super().run()
class clean_cosmosis(setuptools.Command):
description = "Run the CosmoSIS clean process"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print("Running CosmoSIS main library clean command")
cosmosis_src_dir = get_COSMOSIS_SRC_DIR()
env = {"COSMOSIS_SRC_DIR": cosmosis_src_dir,}
subprocess.check_call(["make", "clean"], env=env, cwd="cosmosis")
class install_cosmosis(setuptools.command.install.install):
description = "Run the CosmoSIS install process"
def run(self):
make_cosmosis()
super().run()
class develop_cosmosis(setuptools.command.develop.develop):
description = "Install CosmoSIS in editable mode"
def run(self):
make_cosmosis()
super().run()
requirements = [
"pyyaml",
"emcee",
"numpy",
"scipy",
"matplotlib",
"pybind11",
"pyyaml",
"scipy",
"threadpoolctl",
"emcee",
"dynesty",
"zeus-mcmc",
"nautilus-sampler>=1.0.1",
"dulwich",
"scikit-learn",
"future",
"Py-BOBYQA",
]
all_package_files = (datablock_libs + sampler_libs
+ c_headers + cc_headers + f90_mods
+ compilers_config + testing_files + other_files)
setuptools.setup(name = 'cosmosis',
description = "The CosmoSIS parameter estimation library.",
author = "Joe Zuntz",
author_email = "joezuntz@googlemail.com",
url = "https://github.com/joezuntz/cosmosis",
packages = setuptools.find_packages(),
package_data = {"cosmosis" : all_package_files},
scripts = scripts,
install_requires = requirements,
cmdclass={
"build_cosmosis": build_cosmosis,
"build_py": build_py_cosmosis,
"install": install_cosmosis,
"develop": develop_cosmosis,
"clean": clean_cosmosis,
},
version=version,
)