1#!/usr/bin/env python 2 3import os 4 5from setuptools import setup 6from distutils.command.build_ext import build_ext as _build_ext 7from setuptools.command.bdist_egg import bdist_egg as _bdist_egg 8from setuptools.extension import Extension 9 10from autogen import rebuild 11from autogen.paths import include_dirs, library_dirs 12 13ext_kwds = dict(include_dirs=include_dirs(), library_dirs=library_dirs()) 14 15 16if "READTHEDOCS" in os.environ: 17 # When building with readthedocs, disable optimizations to decrease 18 # resource usage during build 19 ext_kwds["extra_compile_args"] = ["-O0"] 20 21 # Print PARI/GP defaults and environment variables for debugging 22 from subprocess import Popen, PIPE 23 Popen(["gp", "-f", "-q"], stdin=PIPE).communicate(b"default()") 24 for item in os.environ.items(): 25 print("%s=%r" % item) 26 27 28# Adapted from Cython's new_build_ext 29class build_ext(_build_ext): 30 def finalize_options(self): 31 # Generate auto-generated sources from pari.desc 32 rebuild() 33 34 self.directives = { 35 "autotestdict.cdef": True, 36 "binding": True, 37 "cdivision": True, 38 "language_level": 2, 39 } 40 41 _build_ext.finalize_options(self) 42 43 def run(self): 44 # Run Cython 45 from Cython.Build.Dependencies import cythonize 46 self.distribution.ext_modules[:] = cythonize( 47 self.distribution.ext_modules, 48 compiler_directives=self.directives) 49 50 _build_ext.run(self) 51 52 53class no_egg(_bdist_egg): 54 def run(self): 55 from distutils.errors import DistutilsOptionError 56 raise DistutilsOptionError("The package cypari2 will not function correctly when built as egg. Therefore, it cannot be installed using 'python setup.py install' or 'easy_install'. Instead, use 'pip install' to install cypari2.") 57 58 59with open('README.rst') as f: 60 README = f.read() 61 62with open('VERSION') as f: 63 VERSION = f.read().strip() 64 65 66setup( 67 name='cypari2', 68 version=VERSION, 69 setup_requires=['Cython>=0.28'], 70 install_requires=['cysignals>=1.7'], 71 description="A Python interface to the number theory library PARI/GP", 72 long_description=README, 73 url="https://github.com/sagemath/cypari2", 74 author="Luca De Feo, Vincent Delecroix, Jeroen Demeyer, Vincent Klein", 75 author_email="sage-devel@googlegroups.com", 76 license='GNU General Public License, version 2 or later', 77 ext_modules=[Extension("*", ["cypari2/*.pyx"], **ext_kwds)], 78 keywords='PARI/GP number theory', 79 packages=['cypari2'], 80 package_dir={'cypari2': 'cypari2'}, 81 package_data={'cypari2': ['declinl.pxi', '*.pxd', '*.h']}, 82 cmdclass=dict(build_ext=build_ext, bdist_egg=no_egg) 83) 84