-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
59 lines (46 loc) · 1.48 KB
/
setup.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
import platform
import os
from os.path import join
from setuptools import Extension, setup
import numpy as np
from numpy.distutils.misc_util import get_info
source_files = [
"pyhtnorm/_htnorm.pyx",
"src/htnorm_rng.c",
"src/htnorm_distributions.c",
"src/htnorm.c"
]
macros = [('NPY_NO_DEPRECATED_API', 0)]
if os.getenv("BUILD_WITH_COVERAGE", None):
macros.append(('CYTHON_TRACE_NOGIL', 1))
if platform.system() == 'Windows':
compile_args = ['/O2']
else:
compile_args = ['-O2', '-std=c99']
# https://numpy.org/devdocs/reference/random/examples/cython/setup.py.html
include_path = np.get_include()
lib_dirs = [
join(include_path, '..', '..', 'random', 'lib'), *get_info('npymath')['library_dirs'],
]
platform_lib_dirs = {
"Linux": ["/usr/lib"],
"Darwin": ["/usr/local/opt/lapack/lib", "/usr/local/opt/openblas/lib"],
"Windows": [],
}
lib_dirs.extend(platform_lib_dirs[platform.system()])
if conda_prefix := os.getenv("MAMBA_ROOT_PREFIX", None):
lib_dirs.append(f"{conda_prefix}/envs/pyhtnorm-dev/lib")
if user_defined_libs_dir := os.getenv("PYHT_LIBS_DIR", None):
lib_dirs.append(user_defined_libs_dir)
extensions = [
Extension(
"pyhtnorm._htnorm",
sources=source_files,
include_dirs=[include_path, "./include", "./src"],
library_dirs=lib_dirs,
libraries=['npyrandom', 'npymath', 'openblas', 'lapack'],
define_macros=macros,
extra_compile_args=compile_args,
),
]
setup(ext_modules=extensions)