-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.py
109 lines (83 loc) · 2.99 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
import re
import os
import sys
import numpy
import platform
from setuptools import setup
from distutils.extension import Extension
from distutils.command.build_ext import build_ext
from Cython.Build import cythonize
if sys.version_info[0] >= 3:
import builtins
else:
import __builtin__ as builtins
# Set global variable st we in can import the package before
# the extensions are built. Taken from numpy:
# https://github.com/numpy/numpy/blob/master/setup.py
builtins.___SETUP___ = True
import dictlearn
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, 'dictlearn/__init__.py'), 'r') as fd:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
fd.read(), re.MULTILINE).group(1)
def sources(which=''):
sources_base = os.path.join(dir_path, 'dictlearn/_dictlearn')
if which == 'hessian':
cython_sources = ['hessian.pyx']
source_files = []
else:
cython_sources = ['_dictlearn.pyx']
source_files = ['omp_cholesky.c', 'omp_batch.c',
'common.c', 'bestexemplar.c']
return [os.path.join(sources_base, source)
for source in cython_sources + source_files]
COMPILE_ARGS = {
'unix': ['-fopenmp', '-O3'],
'msvc': ['/openmp', '/O2']
}
class build_ext_sub(build_ext):
def compile_args(self, compiler):
if platform.system() == 'Darwin':
args = ['-Xpreprocessor', '-fopenmp', '-O3']
else:
args = COMPILE_ARGS.get(compiler, [])
return args
def build_extensions(self):
compiler = self.compiler.compiler_type
for ext in self.extensions:
ext.extra_compile_args = self.compile_args(compiler)
build_ext.build_extensions(self)
def extensions():
exts = [
Extension('dictlearn._dictlearn._dictlearn', sources()),
Extension('dictlearn._dictlearn.hessian', sources('hessian'))
]
for ext in exts:
ext.include_dirs.append(numpy.get_include())
return cythonize(exts)
setup(
name='dictlearn',
version=version,
description=dictlearn.__doc__,
ext_modules=extensions(),
packages=['dictlearn', 'dictlearn._dictlearn'],
cmdclass={'build_ext': build_ext_sub},
install_requires=open('requirements.txt').read().split(),
license='MIT',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: Unix',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Scientific/Engineering'
]
)