33import subprocess
44import sys
55import platform
6- from setuptools import setup
7- from setuptools .command .install import install as _install
8- from setuptools .command .build_ext import build_ext as _build_ext
9- from setuptools .command .bdist_wheel import bdist_wheel as _bdist_wheel
10- from setuptools .command .build import build as _build
116
127# Make sure the system has the right Python version.
138if sys .version_info [:2 ] < (3 , 9 ):
@@ -27,6 +22,37 @@ def _get_limited_api():
2722
2823limited_api = _get_limited_api ()
2924
25+ # use setuptools by default as per the official advice at:
26+ # packaging.python.org/en/latest/current.html#packaging-tool-recommendations
27+ use_setuptools = True
28+ # set the environment variable USE_DISTUTILS=True to force the use of distutils
29+ use_distutils = getenv ('USE_DISTUTILS' )
30+ if use_distutils is not None :
31+ if use_distutils .lower () == 'true' :
32+ use_setuptools = False
33+ else :
34+ print ("Value {} for USE_DISTUTILS treated as False" .
35+ format (use_distutils ))
36+
37+ if use_setuptools :
38+ try :
39+ from setuptools import setup
40+ from setuptools .command .install import install as _install
41+ from setuptools .command .build_ext import build_ext as _build_ext
42+ except ImportError :
43+ use_setuptools = False
44+ else :
45+ try :
46+ from setuptools .command .build import build as _build
47+ except ImportError :
48+ from distutils .command .build import build as _build
49+
50+ if not use_setuptools :
51+ from distutils .core import setup
52+ from distutils .command .install import install as _install
53+ from distutils .command .build_ext import build_ext as _build_ext
54+ from distutils .command .build import build as _build
55+
3056cmake_opts = [("PYTHON_BIN" , sys .executable ),
3157 ("CMAKE_INSTALL_RPATH_USE_LINK_PATH" , "yes" )]
3258cmake_generator = [None ]
@@ -187,20 +213,27 @@ def run(self):
187213 _install .run (self )
188214 self .cmake_install ()
189215
190- class BdistWheelWithCmake (_bdist_wheel ):
191- def finalize_options (self ):
192- _bdist_wheel .finalize_options (self )
193- self .root_is_pure = False
194- if limited_api :
195- self .py_limited_api = f"cp{ "" .join (str (c ) for c in limited_api )} "
196-
197216cmdclass = {
198- 'build' : BuildWithCmake ,
199- 'build_ext' : BuildExtWithCmake ,
200- 'install' : InstallWithCmake ,
201- 'bdist_wheel' : BdistWheelWithCmake ,
202- }
203-
217+ 'build' : BuildWithCmake ,
218+ 'build_ext' : BuildExtWithCmake ,
219+ 'install' : InstallWithCmake ,
220+ }
221+
222+ try :
223+ try :
224+ from setuptools .command .bdist_wheel import bdist_wheel
225+ except ImportError :
226+ from wheel .bdist_wheel import bdist_wheel
227+
228+ class BdistWheelWithCmake (bdist_wheel ):
229+ def finalize_options (self ):
230+ bdist_wheel .finalize_options (self )
231+ self .root_is_pure = False
232+ if limited_api :
233+ self .py_limited_api = "cp" + "" .join (str (c ) for c in limited_api )
234+ cmdclass ["bdist_wheel" ] = BdistWheelWithCmake
235+ except ImportError :
236+ pass
204237
205238long_description = '''
206239SymEngine is a standalone fast C++ symbolic manipulation library.
@@ -215,13 +248,13 @@ def finalize_options(self):
215248setup (name = "symengine" ,
216249 version = "0.14.1" ,
217250 description = "Python library providing wrappers to SymEngine" ,
218- setup_requires = ['cython>=0.29.24' , 'setuptools>=70.1.0 ' ],
251+ setup_requires = ['cython>=0.29.24' , 'setuptools' ],
219252 long_description = long_description ,
220253 author = "SymEngine development team" ,
221254222255 license = "MIT" ,
223256 url = "https://github.com/symengine/symengine.py" ,
224- python_requires = " >=3.9,<4" ,
257+ python_requires = ' >=3.9,<4' ,
225258 zip_safe = False ,
226259 packages = [],
227260 cmdclass = cmdclass ,
0 commit comments