-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
71 lines (58 loc) · 2.09 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
"""
This module is used to build a Python extension module named "pism_dbg" using setuptools.
The module uses the GSL (GNU Scientific Library) and optionally OpenMP for parallel processing.
The source code for the extension module is written in C++ and includes several source files.
initialize_options()
Initializes options for the build process. If no extension modules are defined, it initializes an empty list and adds the "pism_dbg" extension to it.
run()
Runs the build_ext command before running the original build_py command.
"""
import os
import numpy
from setuptools import Extension
from setuptools.command.build_py import build_py as _build_py
# If the user set NO_OPENMP, proceed with these options. Otherwise add options clang uses.
libraries = ["gsl", "gslcblas"]
extra_compile_args = ["-O3", "-ffast-math", "-Wall"]
try:
os.environ["NO_OPENMP"]
except:
extra_compile_args.append("-fopenmp")
libraries.append("gomp")
class build_py(_build_py):
"""
Class used to build extentions.
"""
def run(self):
"""
Execute the build_ext command before running the original build_py command.
Returns
-------
Any
The result of the superclass's run method.
"""
self.run_command("build_ext")
return super().run()
def initialize_options(self):
"""
Initialize options.
"""
super().initialize_options()
if self.distribution.ext_modules is None:
self.distribution.ext_modules = []
self.distribution.ext_modules.append(
Extension(
"drainage_basin_generator",
sources=[
"python/drainage_basin_generator.pyx",
"src/upslope_area.cc",
"src/accumulated_flow.cc",
"src/initialize_mask.cc",
"src/DEM.cc",
],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
language="c++",
)
)