-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
81 lines (73 loc) · 2.71 KB
/
Copy pathsetup.py
File metadata and controls
81 lines (73 loc) · 2.71 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
setup.py
"""
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from Cython.Build import cythonize
from Cython.Compiler.Errors import CompileError
import numpy as np
import warnings
import platform
import os
system = platform.system().lower()
extra_compile_args = ["/O2"] if system == "windows" else ["-O3"]
extra_libraries = [] if system == "windows" else ["m"] # link with libm on POSIX
include_dirs = [np.get_include(), "surfquakecore/cython_module"]
def try_cythonize(ext: Extension):
"""Try compiling one extension; warn and skip on error."""
try:
return cythonize(
[ext],
compiler_directives={
"language_level": 3,
"boundscheck": False,
"wraparound": False,
"cdivision": True,
"nonecheck": False,
},
)
except CompileError as e:
warnings.warn(f"Warning Could not compile {ext.name}: {e}. Skipping.")
except Exception as e:
warnings.warn(f"Warning Unexpected error compiling {ext.name}: {e}. Skipping.")
return []
# Explicit list of pyx modules to build
ext_specs = [
# existing
("surfquakecore.cython_module.hampel", "surfquakecore/cython_module/hampel.pyx"),
("surfquakecore.cython_module.whiten", "surfquakecore/cython_module/whiten.pyx"),
# CF modules
("surfquakecore.cython_module.rec_filter", "surfquakecore/cython_module/rec_filter.pyx"),
("surfquakecore.cython_module.lib_rec_hos", "surfquakecore/cython_module/lib_rec_hos.pyx"),
("surfquakecore.cython_module.lib_rec_rms", "surfquakecore/cython_module/lib_rec_rms.pyx"),
("surfquakecore.cython_module.lib_rosenberger", "surfquakecore/cython_module/lib_rosenberger.pyx"),
("surfquakecore.cython_module.lib_rec_cc", "surfquakecore/cython_module/lib_rec_cc.pyx"),
]
extensions = []
for modname, relsrc in ext_specs:
if not os.path.isfile(relsrc):
warnings.warn(f"Warning Source not found for {modname}: {relsrc}. Skipping.")
continue
ext = Extension(
name=modname,
sources=[relsrc], # relative path!
include_dirs=include_dirs,
language="c",
extra_compile_args=extra_compile_args,
libraries=extra_libraries,
)
extensions.extend(try_cythonize(ext))
class BuildExt(build_ext):
"""Keep hooks open for custom behavior if needed."""
pass
setup(
name="surfquake",
version="1.5.0",
description="SurfQuake core with Cython accelerations",
packages=["surfquakecore", "surfquakecore.cython_module"],
cmdclass={"build_ext": BuildExt},
ext_modules=extensions,
include_dirs=include_dirs,
)