|
39 | 39 | fh.write("numpy_build_version = '%s'\n" % numpy.__version__)
|
40 | 40 | except ImportError:
|
41 | 41 | pass
|
42 |
| - |
| 42 | + |
43 | 43 | lib_dirs = []
|
44 | 44 | inc_dirs = [np.get_include(), op.join('framestream')]
|
45 | 45 | libs = [] # Pre-built libraries ONLY, like python36.so
|
|
59 | 59 | extra_cflags = []
|
60 | 60 | extra_link_args = []
|
61 | 61 |
|
62 |
| -numexpr_extension = Extension('numexpr.interpreter', |
63 |
| - include_dirs=inc_dirs, |
64 |
| - define_macros=def_macros, |
65 |
| - sources=sources, |
66 |
| - library_dirs=lib_dirs, |
67 |
| - libraries=libs, |
68 |
| - extra_compile_args=extra_cflags, |
69 |
| - extra_link_args=extra_link_args,) |
| 62 | +def parse_site_cfg(): |
| 63 | + """ |
| 64 | + Parses `site.cfg`, if it exists, to determine the location of Intel oneAPI MKL. |
| 65 | +
|
| 66 | + To compile NumExpr with MKL (VML) support, typically you need to copy the |
| 67 | + provided `site.cfg.example` to `site.cfg` and then edit the paths in the |
| 68 | + configuration lines for `include_dirs` and `library_dirs` paths to point |
| 69 | + to the appropriate directories on your machine. |
| 70 | + """ |
| 71 | + import configparser |
| 72 | + site = configparser.ConfigParser() |
| 73 | + if not op.isfile('site.cfg'): |
| 74 | + return |
| 75 | + |
| 76 | + site.read('site.cfg') |
| 77 | + |
| 78 | + if 'mkl' in site.sections(): |
| 79 | + inc_dirs.extend( |
| 80 | + site['mkl']['include_dirs'].split(os.pathsep)) |
| 81 | + lib_dirs.extend( |
| 82 | + site['mkl']['library_dirs'].split(os.pathsep)) |
| 83 | + libs.extend( |
| 84 | + site['mkl']['libraries'].split(os.pathsep)) |
| 85 | + def_macros.append(('USE_VML', None)) |
| 86 | + |
70 | 87 |
|
71 | 88 | def setup_package():
|
| 89 | + |
| 90 | + parse_site_cfg() |
| 91 | + |
| 92 | + numexpr_extension = Extension('numexpr.interpreter', |
| 93 | + include_dirs=inc_dirs, |
| 94 | + define_macros=def_macros, |
| 95 | + sources=sources, |
| 96 | + library_dirs=lib_dirs, |
| 97 | + libraries=libs, |
| 98 | + extra_compile_args=extra_cflags, |
| 99 | + extra_link_args=extra_link_args,) |
| 100 | + |
| 101 | + |
72 | 102 | metadata = dict(
|
73 | 103 | name = 'numexpr',
|
74 | 104 | version = version,
|
@@ -111,115 +141,6 @@ def setup_package():
|
111 | 141 | ],
|
112 | 142 |
|
113 | 143 | )
|
114 |
| - |
115 |
| - # def configuration(): |
116 |
| - # from numpy.distutils.misc_util import Configuration, dict_append |
117 |
| - # from numpy.distutils.system_info import system_info |
118 |
| - |
119 |
| - # config = Configuration('numexpr') |
120 |
| - |
121 |
| - # #try to find configuration for MKL, either from environment or site.cfg |
122 |
| - # if op.exists('site.cfg'): |
123 |
| - # mkl_config_data = config.get_info('mkl') |
124 |
| - # # Some version of MKL needs to be linked with libgfortran. |
125 |
| - # # For this, use entries of DEFAULT section in site.cfg. |
126 |
| - # default_config = system_info() |
127 |
| - # dict_append(mkl_config_data, |
128 |
| - # libraries=default_config.get_libraries(), |
129 |
| - # library_dirs=default_config.get_lib_dirs()) |
130 |
| - # else: |
131 |
| - # mkl_config_data = {} |
132 |
| - |
133 |
| - # # setup information for C extension |
134 |
| - # if os.name == 'nt': |
135 |
| - # pthread_win = ['numexpr/win32/pthread.c'] |
136 |
| - # else: |
137 |
| - # pthread_win = [] |
138 |
| - # extension_config_data = { |
139 |
| - # 'sources': ['numexpr/interpreter.cpp', |
140 |
| - # 'numexpr/module.cpp', |
141 |
| - # 'numexpr/numexpr_object.cpp'] + pthread_win, |
142 |
| - # 'depends': ['numexpr/interp_body.cpp', |
143 |
| - # 'numexpr/complex_functions.hpp', |
144 |
| - # 'numexpr/interpreter.hpp', |
145 |
| - # 'numexpr/module.hpp', |
146 |
| - # 'numexpr/msvc_function_stubs.hpp', |
147 |
| - # 'numexpr/numexpr_config.hpp', |
148 |
| - # 'numexpr/numexpr_object.hpp'], |
149 |
| - # 'libraries': ['m'], |
150 |
| - # 'extra_compile_args': ['-funroll-all-loops', ], |
151 |
| - # } |
152 |
| - # dict_append(extension_config_data, **mkl_config_data) |
153 |
| - # if 'library_dirs' in mkl_config_data: |
154 |
| - # library_dirs = ':'.join(mkl_config_data['library_dirs']) |
155 |
| - # config.add_extension('interpreter', **extension_config_data) |
156 |
| - # config.set_options(quiet=True) |
157 |
| - |
158 |
| - # config.make_config_py() |
159 |
| - # config.add_subpackage('tests', 'numexpr/tests') |
160 |
| - |
161 |
| - # #version handling |
162 |
| - # config.get_version('numexpr/version.py') |
163 |
| - # return config |
164 |
| - |
165 |
| - |
166 |
| - # class cleaner(setuptools.command.clean): |
167 |
| - # |
168 |
| - # def run(self): |
169 |
| - # # Recursive deletion of build/ directory |
170 |
| - # path = localpath("build") |
171 |
| - # try: |
172 |
| - # shutil.rmtree(path) |
173 |
| - # except Exception: |
174 |
| - # debug("Failed to remove directory %s" % path) |
175 |
| - # else: |
176 |
| - # debug("Cleaned up %s" % path) |
177 |
| - # |
178 |
| - # # Now, the extension and other files |
179 |
| - # try: |
180 |
| - # import imp |
181 |
| - # except ImportError: |
182 |
| - # if os.name == 'posix': |
183 |
| - # paths = [localpath("numexpr/interpreter.so")] |
184 |
| - # else: |
185 |
| - # paths = [localpath("numexpr/interpreter.pyd")] |
186 |
| - # else: |
187 |
| - # paths = [] |
188 |
| - # for suffix, _, _ in imp.get_suffixes(): |
189 |
| - # if suffix == '.py': |
190 |
| - # continue |
191 |
| - # paths.append(localpath("numexpr", "interpreter" + suffix)) |
192 |
| - # paths.append(localpath("numexpr/__config__.py")) |
193 |
| - # paths.append(localpath("numexpr/__config__.pyc")) |
194 |
| - # for path in paths: |
195 |
| - # try: |
196 |
| - # os.remove(path) |
197 |
| - # except Exception: |
198 |
| - # debug("Failed to clean up file %s" % path) |
199 |
| - # else: |
200 |
| - # debug("Cleaning up %s" % path) |
201 |
| - # |
202 |
| - # setuptools.clean.run(self) |
203 |
| - |
204 |
| - # class build_ext(numpy_build_ext): |
205 |
| - # def build_extension(self, ext): |
206 |
| - # # at this point we know what the C compiler is. |
207 |
| - # if self.compiler.compiler_type == 'msvc' or self.compiler.compiler_type == 'intelemw': |
208 |
| - # ext.extra_compile_args = [] |
209 |
| - # # also remove extra linker arguments msvc doesn't understand |
210 |
| - # ext.extra_link_args = [] |
211 |
| - # # also remove gcc math library |
212 |
| - # ext.libraries.remove('m') |
213 |
| - # numpy_build_ext.build_extension(self, ext) |
214 |
| - |
215 |
| - |
216 |
| - # metadata['cmdclass'] = { |
217 |
| - # 'build_ext': build_ext, |
218 |
| - # # 'clean': cleaner, |
219 |
| - # 'build_py': build_py, |
220 |
| - # } |
221 |
| - # metadata['configuration'] = configuration |
222 |
| - |
223 | 144 | setup(**metadata)
|
224 | 145 |
|
225 | 146 |
|
|
0 commit comments