-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path_build.py
122 lines (98 loc) · 3.5 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
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
"""Install script for Hazma."""
# pylint: disable=invalid-name
from typing import List
from Cython.Build import cythonize
from setuptools import Extension
from setuptools.command.build_py import build_py as _build_py
VERSION = "2.0.0-rc1"
class build_py(_build_py):
def run(self):
self.run_command("build_ext")
return super().run()
def initialize_options(self) -> None:
super().initialize_options()
if self.distribution.ext_modules == None:
self.distribution.ext_modules = []
if self.distribution.include_dirs == None:
self.distribution.include_dirs = []
import numpy
self.distribution.include_dirs.append(numpy.get_include())
extensions = []
# Cython utilities
extensions += make_extension(["_utils"], ["boost"])
# Gamma-Ray Helper
extensions += make_extension(
["_gamma_ray"], ["gamma_ray_generator", "gamma_ray_fsr"], cpp=True
)
# Phase space
extensions += make_extension(
["_phase_space"], ["generator", "histogram", "modifiers"], cpp=True
)
# Field Theory helper
extensions += make_extension(
["field_theory_helper_functions"],
["common_functions", "three_body_phase_space"],
cpp=True,
)
# Positron
extensions += make_extension(
["_positron"], ["positron_muon", "positron_charged_pion", "positron_decay"]
)
# Neutrino
extensions += make_extension(["_neutrino"], ["charged_pion", "muon"])
# Decay Spectra
extensions += make_extension(
["spectra", "_photon"],
["_muon", "_pion", "_rho", "_kaon", "_eta", "_omega", "_eta_prime", "_phi"],
)
extensions += make_extension(
["spectra", "_positron"],
["_muon", "_pion"],
)
extensions += make_extension(
["spectra", "_neutrino"],
["_muon", "_pion", "_neutrino"],
)
# Scalar mediator
extensions += make_extension(
["scalar_mediator"],
[
"scalar_mediator_decay_spectrum",
"scalar_mediator_positron_spec",
"_c_scalar_mediator_cross_sections",
],
)
# Vector mediator
extensions += make_extension(
["vector_mediator"],
[
"vector_mediator_decay_spectrum",
"vector_mediator_positron_spec",
"_c_vector_mediator_cross_sections",
],
)
# RH-neutrino
# extensions += [
# Extension(
# "hazma.rh_neutrino._rh_neutrino_fsr_four_body",
# sources=["hazma/rh_neutrino/_rh_neutrino_fsr_four_body.pyx"],
# extra_compile_args=["-g", "-std=c++11"],
# language="c++",
# )
# ]
self.distribution.ext_modules.extend(extensions)
def make_extension(module: List[str], sources: List[str], cpp=False):
"""Build a Cython extension module."""
package = ".".join(["hazma", *module])
path = "/".join(["hazma", *module])
extensions = []
for src in sources:
m = package + "." + src
p = [path + "/" + src + ".pyx"]
if cpp:
exts = Extension(m, p, extra_compile_args=["-std=c++11"], language="c++")
else:
exts = Extension(m, p)
for ext in cythonize(exts):
extensions.append(ext)
return extensions