-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
154 lines (127 loc) · 5.28 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import os
from distutils.sysconfig import get_python_inc
from distutils.util import get_platform
import platform
import sys
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext
def get_config():
# Import numpy here, only when headers are needed
import numpy as np
from numpy.distutils.system_info import blas_info
incs = ['spams_wrap']
for x in ['linalg', 'prox', 'decomp', 'dictLearn']:
incs.append(os.path.join('spams_wrap', x))
incs.append(np.get_include())
incs.append(get_python_inc())
incs.extend(blas_info().get_include_dirs())
cc_flags = ['-fPIC', '-Wunused-variable', '-Wno-uninitialized']
if sys.maxsize > 2**32:
cc_flags.append('-m64')
else:
cc_flags.append('-m32')
for _ in np.__config__.blas_opt_info.get('extra_compile_args', []):
if _ not in cc_flags:
cc_flags.append(_)
for _ in np.__config__.lapack_opt_info.get('extra_compile_args', []):
if _ not in cc_flags:
cc_flags.append(_)
link_flags = []
for _ in np.__config__.blas_opt_info.get('extra_link_args', []):
if _ not in link_flags:
link_flags.append(_)
for _ in np.__config__.lapack_opt_info.get('extra_link_args', []):
if _ not in link_flags:
link_flags.append(_)
libs = ['stdc++']
is_mkl = False
for lib in np.__config__.blas_opt_info.get('libraries', []):
if 'mkl' in lib:
is_mkl = True
break
libdirs = np.distutils.system_info.blas_info().get_lib_dirs()
if is_mkl:
for _ in np.__config__.blas_opt_info.get('include_dirs', []):
if _ not in incs:
incs.append(_)
for _ in np.__config__.blas_opt_info.get('library_dirs', []):
if _ not in libdirs:
libdirs.append(_)
libs.extend(['mkl_rt'])
else:
libs.extend(['blas', 'lapack'])
if platform.system() != 'Darwin':
cc_flags.append('-fopenmp')
link_flags.append('-fopenmp')
return incs, libs, libdirs, cc_flags, link_flags
class CustomBuildExtCommand(build_ext):
""" build_ext command to use when numpy headers are needed. """
def run(self):
# Now that the requirements are installed, get everything from numpy
incs, libs, libdirs, cc_flags, link_flags = get_config()
# Add everything requires for build
self.extensions[0].include_dirs.extend(incs)
self.extensions[0].libraries.extend(libs)
self.extensions[0].library_dirs.extend(libdirs)
self.extensions[0].extra_compile_args.extend(cc_flags)
self.extensions[0].extra_link_args.extend(link_flags)
# Call original build_ext command
build_ext.run(self)
def get_extension():
# Generic initialization of the extension
spams_wrap = Extension('_spams_wrap',
sources=['spams_wrap/spams_wrap.cpp'],
extra_compile_args=['-DNDEBUG',
'-DUSE_BLAS_LIB',
'-std=c++11'],
language='c++',
depends=['spams_wrap/spams.h'])
return [spams_wrap]
def mkhtml(d=None, base='sphinx'):
if d is None:
d = base
else:
d = os.path.join(base, d)
if not os.path.isdir(base):
return []
hdir = d
l1 = os.listdir(hdir)
l = []
for s in l1:
s = os.path.join(d, s)
if not os.path.isdir(s):
l.append(s)
return l
long_description = """Python interface for SPArse Modeling Software (SPAMS),
an optimization toolbox for solving various sparse estimation problems."""
opts = dict(name='python-spams',
version='2.6.1.11',
description='Python interface for SPAMS',
long_description=long_description,
author='Julien Mairal',
author_email='[email protected]',
url='http://spams-devel.gforge.inria.fr/',
license='GPLv3',
setup_requires=['Cython>=0.29', 'numpy>=1.12'],
install_requires=['Cython>=0.29', 'numpy>=1.12',
'Pillow>=6.0', 'scipy>=1.0', 'six>=1.12'],
packages=find_packages(),
cmdclass={'build_ext': CustomBuildExtCommand},
ext_modules=get_extension(),
data_files=[('tests', ['tests/test_spams.py',
'tests/test_decomp.py',
'tests/test_dictLearn.py',
'tests/test_linalg.py',
'tests/test_prox.py',
'tests/test_utils.py']),
('doc', ['doc/doc_spams.pdf']),
('doc/sphinx/_sources',
mkhtml(d='_sources', base='doc/sphinx')),
('doc/sphinx/_static', mkhtml(d='_static',
base='doc/sphinx')),
('doc/sphinx', mkhtml(base='doc/sphinx')),
('doc/html', mkhtml(base='doc/html')),
('tests', ['data/boat.png', 'data/lena.png'])],
include_package_data=True,
zip_safe=True)
setup(**opts)