1#!/usr/bin/env python 2################################################################### 3# NumExpr - Fast numerical array expression evaluator for NumPy. 4# 5# License: MIT 6# Author: See AUTHORS.txt 7# 8# See LICENSE.txt and LICENSES/*.txt for details about copyright and 9# rights to use. 10#################################################################### 11 12import sys, os, os.path as op, io 13# import setuptools 14from setuptools import setup, find_packages, Extension 15import platform 16import numpy as np 17 18if sys.version_info < (3, 6): 19 raise RuntimeError("NumExpr requires Python 3.6 or greater") 20 21with open('requirements.txt') as f: 22 requirements = f.read().splitlines() 23 24with io.open('README.rst', encoding='utf-8') as f: 25 LONG_DESCRIPTION = f.read() 26 27major_ver = 2 28minor_ver = 8 29nano_ver = 0 30branch = '' 31 32version = '%d.%d.%d%s' % (major_ver, minor_ver, nano_ver, branch) 33with open('numexpr/version.py', 'w') as fh: 34 fh.write('# THIS FILE IS GENERATED BY `SETUP.PY`\n') 35 fh.write("version = '%s'\n" % version) 36 try: 37 import numpy 38 fh.write("numpy_build_version = '%s'\n" % numpy.__version__) 39 except ImportError: 40 pass 41 42lib_dirs = [] 43inc_dirs = [np.get_include(), op.join('framestream')] 44libs = [] # Pre-built libraries ONLY, like python36.so 45clibs = [] 46def_macros = [] 47sources = ['numexpr/interpreter.cpp', 48 'numexpr/module.cpp', 49 'numexpr/numexpr_object.cpp'] 50extra_cflags = [] 51extra_link_args = [] 52 53if platform.uname().system == 'Windows': 54 extra_cflags = ['/O2'] 55 extra_link_args = [] 56 sources.append('numexpr/win32/pthread.c') 57else: 58 extra_cflags = [] 59 extra_link_args = [] 60 61def parse_site_cfg(): 62 """ 63 Parses `site.cfg`, if it exists, to determine the location of Intel oneAPI MKL. 64 65 To compile NumExpr with MKL (VML) support, typically you need to copy the 66 provided `site.cfg.example` to `site.cfg` and then edit the paths in the 67 configuration lines for `include_dirs` and `library_dirs` paths to point 68 to the appropriate directories on your machine. 69 """ 70 import configparser 71 site = configparser.ConfigParser() 72 if not op.isfile('site.cfg'): 73 return 74 75 site.read('site.cfg') 76 77 if 'mkl' in site.sections(): 78 inc_dirs.extend( 79 site['mkl']['include_dirs'].split(os.pathsep)) 80 lib_dirs.extend( 81 site['mkl']['library_dirs'].split(os.pathsep)) 82 libs.extend( 83 site['mkl']['libraries'].split(os.pathsep)) 84 def_macros.append(('USE_VML', None)) 85 86 87def setup_package(): 88 89 parse_site_cfg() 90 91 numexpr_extension = Extension('numexpr.interpreter', 92 include_dirs=inc_dirs, 93 define_macros=def_macros, 94 sources=sources, 95 library_dirs=lib_dirs, 96 libraries=libs, 97 extra_compile_args=extra_cflags, 98 extra_link_args=extra_link_args,) 99 100 101 metadata = dict( 102 name = 'numexpr', 103 version = version, 104 description = 'Fast numerical expression evaluator for NumPy', 105 author = 'David M. Cooke, Francesc Alted, and others', 106 author_email = 'david.m.cooke@gmail.com, faltet@gmail.com', 107 maintainer = 'Robert A. McLeod', 108 maintainer_email = 'robbmcleod@gmail.com', 109 url = 'https://github.com/pydata/numexpr', 110 long_description = LONG_DESCRIPTION, 111 license = 'MIT', 112 packages = find_packages(), 113 install_requires = requirements, 114 setup_requires = requirements, 115 extras_require = { 116 }, 117 libraries = clibs, 118 ext_modules = [ 119 numexpr_extension 120 ], 121 zip_safe = False, 122 classifiers = [ 123 'Development Status :: 6 - Mature', 124 125 'Intended Audience :: Financial and Insurance Industry', 126 'Intended Audience :: Science/Research', 127 128 'License :: OSI Approved :: MIT License', 129 130 'Programming Language :: Python :: 3', 131 'Programming Language :: Python :: 3.6', 132 'Programming Language :: Python :: 3.7', 133 'Programming Language :: Python :: 3.8', 134 'Programming Language :: Python :: 3.9', 135 'Programming Language :: Python :: 3.10', 136 # OS 137 'Operating System :: Microsoft :: Windows', 138 'Operating System :: POSIX', 139 'Operating System :: MacOS', 140 ], 141 142 ) 143 setup(**metadata) 144 145 146if __name__ == '__main__': 147 setup_package() 148