Skip to content

Commit

Permalink
followed cython docs to build extensions from pyx or c files based on…
Browse files Browse the repository at this point in the history
… whether or not cython is installed
  • Loading branch information
scotthavens committed Sep 17, 2020
1 parent 82d9663 commit d072f1c
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 381 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
coloredlogs
Cython>=0.28.4
inicheck>=0.9.0,<0.10.0
netCDF4>=1.2.9
numpy>=1.14.0
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r requirements.txt
Cython
coveralls>=1.3.0
tox>=3.14.0
flake8>=3.5.0
Expand Down
27 changes: 19 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext

# Test if compiling with cython or using the C source
try:
from Cython.Distutils import build_ext as _build_ext
except ImportError:
USE_CYTHON = False
else:
USE_CYTHON = True

print('Using Cython {}'.format(USE_CYTHON))
ext = '.pyx' if USE_CYTHON else '.c'


def c_name_from_path(location, name):
return os.path.join(location, name).replace('/', '.')
Expand All @@ -22,10 +33,8 @@ def finalize_options(self):

# Give user option to specify his local compiler name
if "CC" not in os.environ:
# force the compiler to use gcc
os.environ["CC"] = "gcc"


ext_modules = []
extension_params = dict(
extra_compile_args=['-fopenmp', '-O3'],
Expand All @@ -38,7 +47,7 @@ def finalize_options(self):
Extension(
c_name_from_path(source_folder, 'detrended_kriging'),
sources=[os.path.join(source_folder, val) for val in [
"detrended_kriging.pyx",
"detrended_kriging" + ext,
"krige.c",
"lusolv.c",
"array.c"
Expand All @@ -53,7 +62,7 @@ def finalize_options(self):
Extension(
c_name_from_path(source_folder, 'envphys_c'),
sources=[os.path.join(source_folder, val) for val in [
"envphys_c.pyx",
"envphys_c" + ext,
"topotherm.c",
"dewpt.c",
"iwbt.c"
Expand All @@ -68,14 +77,18 @@ def finalize_options(self):
Extension(
c_name_from_path(source_folder, 'wind_c'),
sources=[os.path.join(source_folder, val) for val in [
"wind_c.pyx",
"wind_c" + ext,
"breshen.c",
"calc_wind.c"
]],
**extension_params
),
]

cmdclass = {}
if USE_CYTHON:
cmdclass = {'build_ext': build_ext}

with open('requirements.txt') as requirements_file:
requirements = requirements_file.read()

Expand Down Expand Up @@ -117,9 +130,7 @@ def finalize_options(self):
],
test_suite='smrf.tests',
# tests_require=test_requirements,
cmdclass={
'build_ext': build_ext
},
cmdclass=cmdclass,
ext_modules=ext_modules,
scripts=[
'scripts/update_configs',
Expand Down
350 changes: 175 additions & 175 deletions smrf/envphys/core/envphys_c.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions smrf/envphys/core/envphys_c.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# cython: embedsignature=True
# cython: language_level=3
"""
C implementation of some radiation functions
"""
Expand Down
124 changes: 62 additions & 62 deletions smrf/spatial/dk/detrended_kriging.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions smrf/spatial/dk/detrended_kriging.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# cython: embedsignature=True
# cython: language_level=3
'''
Compiling dk's kriging function
Expand Down
270 changes: 135 additions & 135 deletions smrf/utils/wind/wind_c.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions smrf/utils/wind/wind_c.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: language_level=3
"""
Cython wrapper to the underlying C code
Expand Down

0 comments on commit d072f1c

Please sign in to comment.