1import platform 2import os 3from setuptools import setup, find_packages, Extension 4from setuptools.command.build_ext import build_ext 5 6ON_WINDOWS = platform.system() == 'Windows' 7_comp_args = ["DSHARED=1"] 8sources = ['src/gmpy2.c'] 9 10# Utility function to read the contents of the README file. 11def read(fname): 12 return open(os.path.join(os.path.dirname(__file__), fname)).read() 13 14class Gmpy2Build(build_ext): 15 description = "Build gmpy2 with custom build options" 16 user_options = build_ext.user_options + [ 17 ('fast', None, 18 "Depend on MPFR and MPC internal implementations details" 19 "(even more than the standard build)"), 20 ('gcov', None, "Enable GCC code coverage collection"), 21 ('vector', None, "Include the vector_XXX() functions;" 22 "they are unstable and under active development"), 23 ('mpir', None, "Enable use of mpir library instead of gmp." 24 "gmp is the default on Posix systems while mpir the default on" 25 "Windows and MSVC"), 26 ('static', None, "Enable static linking compile time options."), 27 ('static-dir=', None, "Enable static linking and specify location."), 28 ('gdb', None, "Build with debug symbols."), 29 ] 30 31 def initialize_options(self): 32 build_ext.initialize_options(self) 33 self.fast = False 34 self.gcov = False 35 self.vector = False 36 self.mpir = False 37 self.static = False 38 self.static_dir = False 39 self.gdb = False 40 41 def finalize_options(self): 42 build_ext.finalize_options(self) 43 if self.fast: 44 _comp_args.append('DFAST=1') 45 if self.gcov: 46 if ON_WINDOWS: 47 raise ValueError("Cannot enable GCC code coverage on Windows") 48 _comp_args.append('DGCOV=1') 49 _comp_args.append('O0') 50 _comp_args.append('-coverage') 51 self.libraries.append('gcov') 52 if self.vector: 53 _comp_args.append('DVECTOR=1') 54 if self.static: 55 _comp_args.remove('DSHARED=1') 56 _comp_args.append('DSTATIC=1') 57 if self.gdb: 58 _comp_args.append('ggdb') 59 if self.static_dir: 60 _comp_args.remove('DSHARED=1') 61 _comp_args.append('DSTATIC=1') 62 self.include_dirs.append(self.static_dir + '/include') 63 self.library_dirs.append(self.static_dir + '/lib') 64 65 def build_extensions(self): 66 compiler = self.compiler.compiler_type 67 if compiler == 'mingw32': 68 _comp_args.append('DMSYS2=1') 69 if self.mpir: 70 _comp_args.append('DMPIR=1') 71 self.libraries.append('mpir') 72 self.libraries.remove('gmp') 73 elif self.mpir or ON_WINDOWS: 74 # --mpir or on Windows and MSVC 75 _comp_args.append('DMPIR=1') 76 self.libraries.append('mpir') 77 self.libraries.remove('gmp') 78 if ON_WINDOWS and not self.static: 79 # MSVC shared build 80 _comp_args.append('MSC_USE_DLL') 81 _prefix = '-' if compiler != 'msvc' else '/' 82 for i in range(len(_comp_args)): 83 _comp_args[i] = ''.join([_prefix, _comp_args[i]]) 84 build_ext.build_extensions(self) 85 86extensions = [ 87 Extension('gmpy2.gmpy2', 88 sources=sources, 89 include_dirs=['./src'], 90 libraries=['mpc','mpfr','gmp'], 91 extra_compile_args=_comp_args, 92 ) 93] 94 95cmdclass = {'build_ext': Gmpy2Build} 96 97setup( 98 name="gmpy2", 99 version="2.1.0b5", 100 author="Case Van Horsen", 101 author_email="casevh@gmail.com", 102 cmdclass=cmdclass, 103 license="LGPL-3.0+", 104 url="https://github.com/aleaxit/gmpy", 105 description="gmpy2 interface to GMP/MPIR, MPFR, " 106 "and MPC for Python 2.6+ and 3.4+", 107 long_description=read('README'), 108 zip_safe=False, 109 include_package_data=True, 110 package_data={'gmpy2': [ 111 '*.pxd', 112 'gmpy2.h', 113 ]}, 114 packages=find_packages(), 115 classifiers=[ 116 'Development Status :: 4 - Beta', 117 'Intended Audience :: Developers', 118 'Intended Audience :: Science/Research', 119 'License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)', 120 'Natural Language :: English', 121 'Operating System :: MacOS :: MacOS X', 122 'Operating System :: Microsoft :: Windows', 123 'Operating System :: POSIX', 124 'Programming Language :: C', 125 'Programming Language :: Python :: 2', 126 'Programming Language :: Python :: 2.6', 127 'Programming Language :: Python :: 2.7', 128 'Programming Language :: Python :: 3', 129 'Programming Language :: Python :: 3.4', 130 'Programming Language :: Python :: 3.5', 131 'Programming Language :: Python :: 3.6', 132 'Programming Language :: Python :: 3.7', 133 'Programming Language :: Python :: Implementation :: CPython', 134 'Topic :: Scientific/Engineering :: Mathematics', 135 'Topic :: Software Development :: Libraries :: Python Modules', 136 ], 137 keywords="gmp mpir mpfr mpc multiple-precision arbitrary-precision precision bignum", 138 ext_modules=extensions, 139) 140