-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathsetup.py
61 lines (56 loc) · 1.82 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
60
61
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
from Cython.Build import cythonize
import cyspams
import sys
from os import cpu_count
from os.path import isfile
from configparser import ConfigParser
# parallel compilation
class build_ext(_build_ext):
def run(self):
self.parallel = cpu_count()
_build_ext.run(self)
libraries = []
library_dirs = []
include_dirs = []
extra_compile_args = []
# spams-cython headers
include_dirs.extend(cyspams.get_include())
# OpenBLAS headers
if not isfile('site.cfg'):
print(f'\033[31mFileNotFoundError: cannot find the site.cfg file\033[0m')
exit(1)
config = ConfigParser()
config.read('site.cfg')
try:
libraries.extend([config['openblas']['library']])
library_dirs.extend([config['openblas']['library_dir']])
include_dirs.extend([config['openblas']['include_dir']])
except KeyError as err:
print(f'\033[31mKeyError: cannot find the {err} key in the site.cfg file. See the site.cfg.example file for documentation\033[0m')
exit(1)
if sys.platform.startswith('win32'):
extra_compile_args.extend(['/std:c++14', '/fp:fast'])
if sys.platform.startswith('darwin') or sys.platform.startswith('linux'):
libraries.extend(['stdc++'])
extra_compile_args.extend(['-std=c++14', '-Ofast'])
extensions = [
Extension(
'amico.models',
sources=['amico/models.pyx'],
include_dirs=include_dirs,
libraries=libraries,
library_dirs=library_dirs,
extra_compile_args=extra_compile_args
),
Extension(
'amico.lut',
sources=['amico/lut.pyx'],
extra_compile_args=extra_compile_args
)
]
setup(
cmdclass={'build_ext': build_ext},
ext_modules=cythonize(extensions)
)