Skip to content

Commit

Permalink
Documented build script
Browse files Browse the repository at this point in the history
  • Loading branch information
aaschwanden committed May 17, 2024
1 parent a48e294 commit 7e7de4f
Showing 1 changed file with 52 additions and 20 deletions.
72 changes: 52 additions & 20 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,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
import numpy

# 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"]
extra_link_args=[]
libraries = ["gsl", "gslcblas"]
extra_compile_args = ["-O3", "-ffast-math", "-Wall"]

try:
os.environ["NO_OPENMP"]
except:
extra_compile_args.append('-fopenmp')
libraries.append('gomp')
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 == None:
if self.distribution.ext_modules is None:
self.distribution.ext_modules = []

self.distribution.ext_modules.append(
Extension("pism_dbg",
sources=["python/pism_dbg.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,
extra_link_args=extra_link_args,
language="c++"
)
Extension(
"pism_dbg",
sources=[
"python/pism_dbg.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++",
)
)

0 comments on commit 7e7de4f

Please sign in to comment.