|
10 | 10 | "Python %d.%d detected" % sys.version_info[:2])
|
11 | 11 | sys.exit(-1)
|
12 | 12 |
|
| 13 | +def _get_limited_api(): |
| 14 | + value = os.environ.get("SYMENGINE_PY_LIMITED_API") |
| 15 | + if not value: |
| 16 | + return None |
| 17 | + else: |
| 18 | + version = tuple(map(int, value.split("."))) |
| 19 | + if version < (3, 11): |
| 20 | + raise ValueError(f"symengine needs at least python 3.11 limited API support. Got {value}") |
| 21 | + return version |
| 22 | + |
| 23 | +limited_api = _get_limited_api() |
| 24 | + |
13 | 25 | # use setuptools by default as per the official advice at:
|
14 | 26 | # packaging.python.org/en/latest/current.html#packaging-tool-recommendations
|
15 | 27 | use_setuptools = True
|
@@ -65,6 +77,7 @@ def get_build_dir(dist):
|
65 | 77 | ('build-type=', None, 'build type: Release or Debug'),
|
66 | 78 | ('define=', 'D',
|
67 | 79 | 'options to cmake <var>:<type>=<value>'),
|
| 80 | + ('py-limited-api=', None, 'Use Py_LIMITED_API with given version.'), |
68 | 81 | ]
|
69 | 82 |
|
70 | 83 | def _process_define(arg):
|
@@ -122,6 +135,11 @@ def cmake_build(self):
|
122 | 135 | cmake_cmd.extend(process_opts(cmake_opts))
|
123 | 136 | if not path.exists(path.join(build_dir, "CMakeCache.txt")):
|
124 | 137 | cmake_cmd.extend(self.get_generator())
|
| 138 | + |
| 139 | + if limited_api: |
| 140 | + h = limited_api[0] * 16**6 + limited_api[1] * 16**4 |
| 141 | + cmake_cmd.append(f"-DWITH_PY_LIMITED_API={h}") |
| 142 | + |
125 | 143 | if subprocess.call(cmake_cmd, cwd=build_dir) != 0:
|
126 | 144 | raise OSError("error calling cmake")
|
127 | 145 |
|
@@ -202,11 +220,17 @@ def run(self):
|
202 | 220 | }
|
203 | 221 |
|
204 | 222 | try:
|
205 |
| - from wheel.bdist_wheel import bdist_wheel |
| 223 | + try: |
| 224 | + from setuptools.command.bdist_wheel import bdist_wheel |
| 225 | + except ImportError: |
| 226 | + from wheel.bdist_wheel import bdist_wheel |
| 227 | + |
206 | 228 | class BdistWheelWithCmake(bdist_wheel):
|
207 | 229 | def finalize_options(self):
|
208 | 230 | bdist_wheel.finalize_options(self)
|
209 | 231 | self.root_is_pure = False
|
| 232 | + if limited_api: |
| 233 | + self.py_limited_api = "cp" + "".join(str(c) for c in limited_api) |
210 | 234 | cmdclass["bdist_wheel"] = BdistWheelWithCmake
|
211 | 235 | except ImportError:
|
212 | 236 | pass
|
|
0 commit comments