2828from __future__ import division , print_function , absolute_import
2929import io
3030import re
31-
31+ import os
32+ from os .path import join , exists , dirname
33+ import setuptools
34+ import setuptools .extension
3235
3336with io .open ('mkl/__init__.py' , 'rt' , encoding = 'utf8' ) as file :
3437 VERSION = re .search (r'__version__ = \'(.*?)\'' , file .read ()).group (1 )
3538
36-
3739CLASSIFIERS = """\
3840 Development Status :: 5 - Production/Stable
3941Intended Audience :: Science/Research
5759"""
5860
5961
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+ )
68110
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+ )
70124
71- config .version = VERSION
125+ if have_cython :
126+ extensions = cythonize (extensions , include_path = [join (__file__ , pdir )])
72127
73- return config
128+ return extensions
74129
75130
76131def setup_package ():
77132 from setuptools import setup
78- from numpy .distutils .core import setup
79133 metadata = dict (
80134 name = 'mkl-service' ,
135+ version = VERSION ,
81136 maintainer = "Intel" ,
82137 maintainer_email = "[email protected] " ,
83138 description = "MKL Support Functions" ,
@@ -99,9 +154,10 @@ def setup_package():
99154 platforms = ["Windows" , "Linux" , "Mac OS-X" ],
100155 test_suite = 'nose.collector' ,
101156 python_requires = '>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*' ,
102- setup_requires = ['numpy ' , 'cython' ],
157+ setup_requires = ['setuptools ' , 'cython' ],
103158 install_requires = ['six' ],
104- configuration = configuration ,
159+ packages = setuptools .find_packages (),
160+ ext_modules = get_extensions ()
105161 )
106162 setup (** metadata )
107163
0 commit comments