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
611
712# Make sure the system has the right Python version.
813if sys .version_info [:2 ] < (3 , 9 ):
914 print ("SymEngine requires Python 3.9 or newer. "
1015 "Python %d.%d detected" % sys .version_info [:2 ])
1116 sys .exit (- 1 )
1217
13- # use setuptools by default as per the official advice at:
14- # packaging.python.org/en/latest/current.html#packaging-tool-recommendations
15- use_setuptools = True
16- # set the environment variable USE_DISTUTILS=True to force the use of distutils
17- use_distutils = getenv ('USE_DISTUTILS' )
18- if use_distutils is not None :
19- if use_distutils .lower () == 'true' :
20- use_setuptools = False
18+ def _get_limited_api ():
19+ value = os .environ .get ("SYMENGINE_PY_LIMITED_API" )
20+ if not value :
21+ return None
2122 else :
22- print ("Value {} for USE_DISTUTILS treated as False" .
23- format (use_distutils ))
24-
25- if use_setuptools :
26- try :
27- from setuptools import setup
28- from setuptools .command .install import install as _install
29- from setuptools .command .build_ext import build_ext as _build_ext
30- except ImportError :
31- use_setuptools = False
32- else :
33- try :
34- from setuptools .command .build import build as _build
35- except ImportError :
36- from distutils .command .build import build as _build
23+ version = tuple (map (int , value .split ("." )))
24+ if version < (3 , 11 ):
25+ raise ValueError (f"symengine needs at least python 3.11 limited API support. Got { value } " )
26+ return version
3727
38- if not use_setuptools :
39- from distutils .core import setup
40- from distutils .command .install import install as _install
41- from distutils .command .build_ext import build_ext as _build_ext
42- from distutils .command .build import build as _build
28+ limited_api = _get_limited_api ()
4329
4430cmake_opts = [("PYTHON_BIN" , sys .executable ),
4531 ("CMAKE_INSTALL_RPATH_USE_LINK_PATH" , "yes" )]
@@ -92,7 +78,6 @@ def initialize_options(self):
9278 self .symengine_dir = None
9379 self .generator = None
9480 self .build_type = "Release"
95- self .py_limited_api = None
9681
9782 def finalize_options (self ):
9883 _build_ext .finalize_options (self )
@@ -125,12 +110,8 @@ def cmake_build(self):
125110 if not path .exists (path .join (build_dir , "CMakeCache.txt" )):
126111 cmake_cmd .extend (self .get_generator ())
127112
128- if self .py_limited_api :
129- assert self .py_limited_api .startswith ("cp3" )
130- py_ver_minor = int (self .py_limited_api [3 :])
131- if py_ver_minor < 11 :
132- raise ValueError (f"symengine needs at least cp311 limited API support. Got { self .py_limited_api } " )
133- h = 3 * 16 ** 6 + py_ver_minor * 16 ** 4
113+ if limited_api :
114+ h = limited_api [0 ] * 16 ** 6 + limited_api [1 ] * 16 ** 4
134115 cmake_cmd .append (f"-DWITH_PY_LIMITED_API={ h } " )
135116
136117 if subprocess .call (cmake_cmd , cwd = build_dir ) != 0 :
@@ -206,21 +187,20 @@ def run(self):
206187 _install .run (self )
207188 self .cmake_install ()
208189
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+
209197cmdclass = {
210- 'build' : BuildWithCmake ,
211- 'build_ext' : BuildExtWithCmake ,
212- 'install' : InstallWithCmake ,
213- }
214-
215- try :
216- from wheel .bdist_wheel import bdist_wheel
217- class BdistWheelWithCmake (bdist_wheel ):
218- def finalize_options (self ):
219- bdist_wheel .finalize_options (self )
220- self .root_is_pure = False
221- cmdclass ["bdist_wheel" ] = BdistWheelWithCmake
222- except ImportError :
223- pass
198+ 'build' : BuildWithCmake ,
199+ 'build_ext' : BuildExtWithCmake ,
200+ 'install' : InstallWithCmake ,
201+ 'bdist_wheel' : BdistWheelWithCmake ,
202+ }
203+
224204
225205long_description = '''
226206SymEngine is a standalone fast C++ symbolic manipulation library.
@@ -235,13 +215,13 @@ def finalize_options(self):
235215setup (name = "symengine" ,
236216 version = "0.14.1" ,
237217 description = "Python library providing wrappers to SymEngine" ,
238- setup_requires = ['cython>=0.29.24' , 'setuptools' ],
218+ setup_requires = ['cython>=0.29.24' , 'setuptools>=70.1.0 ' ],
239219 long_description = long_description ,
240220 author = "SymEngine development team" ,
241221242222 license = "MIT" ,
243223 url = "https://github.com/symengine/symengine.py" ,
244- python_requires = ' >=3.9,<4' ,
224+ python_requires = " >=3.9,<4" ,
245225 zip_safe = False ,
246226 packages = [],
247227 cmdclass = cmdclass ,
0 commit comments