28
28
from __future__ import division , print_function , absolute_import
29
29
import io
30
30
import re
31
-
31
+ import os
32
+ from os .path import join , exists , dirname
33
+ import setuptools
34
+ import setuptools .extension
32
35
33
36
with io .open ('mkl/__init__.py' , 'rt' , encoding = 'utf8' ) as file :
34
37
VERSION = re .search (r'__version__ = \'(.*?)\'' , file .read ()).group (1 )
35
38
36
-
37
39
CLASSIFIERS = """\
38
40
Development Status :: 5 - Production/Stable
39
41
Intended Audience :: Science/Research
57
59
"""
58
60
59
61
60
- def configuration (parent_package = '' , top_path = None ):
61
- from numpy .distutils .misc_util import Configuration
62
-
63
- config = Configuration (None , parent_package , top_path )
64
- config .set_options (ignore_setup_xxx_py = True ,
65
- assume_default_configuration = True ,
66
- delegate_options_to_subpackages = True ,
67
- quiet = True )
62
+ def get_extensions ():
63
+ try :
64
+ from numpy .distutils .system_info import get_info
65
+ mkl_info = get_info ('mkl' )
66
+ except ImportError :
67
+ mkl_root = os .environ ['MKLROOT' ]
68
+ mkl_info = {
69
+ 'include_dirs' : [join (mkl_root , 'include' )],
70
+ 'library_dirs' : [join (mkl_root , 'lib' ), join (mkl_root , 'lib' , 'intel64' )],
71
+ 'libraries' : ['mkl_rt' ]
72
+ }
73
+
74
+ mkl_include_dirs = mkl_info .get ('include_dirs' , [])
75
+ mkl_library_dirs = mkl_info .get ('library_dirs' , [])
76
+ mkl_libraries = mkl_info .get ('libraries' , ['mkl_rt' ])
77
+
78
+ defs = []
79
+ if any (['mkl_rt' in li for li in mkl_libraries ]):
80
+ #libs += ['dl'] - by default on Linux
81
+ defs += [('USING_MKL_RT' , None )]
82
+
83
+ pdir = 'mkl'
84
+ try :
85
+ from Cython .Build import cythonize
86
+ sources = [join (pdir , '_mkl_service.pyx' )]
87
+ have_cython = True
88
+ except ImportError as e :
89
+ have_cython = False
90
+ sources = [join (pdir , '_mkl_service.c' )]
91
+ if not exists (sources [0 ]):
92
+ raise ValueError (str (e ) + '. ' +
93
+ 'Cython is required to build the initial .c file.' )
94
+
95
+ extensions = []
96
+ extensions .append (
97
+ setuptools .extension .Extension (
98
+ 'mkl._mklinit' ,
99
+ sources = ['mkl/_mklinitmodule.c' ],
100
+ define_macros = defs ,
101
+ include_dirs = mkl_include_dirs ,
102
+ libraries = mkl_libraries ,
103
+ library_dirs = mkl_library_dirs ,
104
+ extra_compile_args = [
105
+ '-DNDEBUG'
106
+ # '-g', '-O2', '-Wall',
107
+ ]
108
+ )
109
+ )
68
110
69
- config .add_subpackage ('mkl' )
111
+ extensions .append (
112
+ setuptools .extension .Extension (
113
+ 'mkl._py_mkl_service' ,
114
+ sources = sources ,
115
+ include_dirs = mkl_include_dirs ,
116
+ library_dirs = mkl_library_dirs ,
117
+ libraries = mkl_libraries ,
118
+ extra_compile_args = [
119
+ '-DNDEBUG'
120
+ # '-g', '-O2', '-Wall',
121
+ ]
122
+ )
123
+ )
70
124
71
- config .version = VERSION
125
+ if have_cython :
126
+ extensions = cythonize (extensions , include_path = [join (__file__ , pdir )])
72
127
73
- return config
128
+ return extensions
74
129
75
130
76
131
def setup_package ():
77
132
from setuptools import setup
78
- from numpy .distutils .core import setup
79
133
metadata = dict (
80
134
name = 'mkl-service' ,
135
+ version = VERSION ,
81
136
maintainer = "Intel" ,
82
137
maintainer_email = "[email protected] " ,
83
138
description = "MKL Support Functions" ,
@@ -99,9 +154,10 @@ def setup_package():
99
154
platforms = ["Windows" , "Linux" , "Mac OS-X" ],
100
155
test_suite = 'nose.collector' ,
101
156
python_requires = '>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*' ,
102
- setup_requires = ['numpy ' , 'cython' ],
157
+ setup_requires = ['setuptools ' , 'cython' ],
103
158
install_requires = ['six' ],
104
- configuration = configuration ,
159
+ packages = setuptools .find_packages (),
160
+ ext_modules = get_extensions ()
105
161
)
106
162
setup (** metadata )
107
163
0 commit comments