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