|
19 | 19 | from setuptools.command.sdist import sdist as _sdist
|
20 | 20 | from setuptools.errors import CompileError, LinkError
|
21 | 21 | import importlib.resources as importlib_resources
|
| 22 | +from wheel.bdist_wheel import bdist_wheel as _bdist_wheel |
22 | 23 |
|
23 | 24 | log = logging.getLogger("setupext")
|
24 | 25 |
|
| 26 | +USE_PY_LIMITED_API = ( |
| 27 | + os.getenv('YT_LIMITED_API', '0') == '1' |
| 28 | + and sys.version_info >= (3, 11) |
| 29 | + and not sysconfig.get_config_var("Py_GIL_DISABLED") |
| 30 | +) |
| 31 | +ABI3_TARGET_VERSION = "".join(str(_) for _ in sys.version_info[:2]) |
| 32 | +ABI3_TARGET_HEX = hex(sys.hexversion & 0xFFFF00F0) |
| 33 | + |
| 34 | + |
25 | 35 | @contextlib.contextmanager
|
26 | 36 | def stdchannel_redirected(stdchannel, dest_filename):
|
27 | 37 | """
|
@@ -433,6 +443,10 @@ def finalize_options(self):
|
433 | 443 | self.include_dirs.append(ewah_bool_utils.get_include())
|
434 | 444 |
|
435 | 445 | define_macros = NUMPY_MACROS
|
| 446 | + if USE_PY_LIMITED_API: |
| 447 | + define_macros.append(("Py_LIMITED_API", ABI3_TARGET_HEX)) |
| 448 | + for ext in self.extensions: |
| 449 | + ext.py_limited_api = True |
436 | 450 |
|
437 | 451 | if self.define is None:
|
438 | 452 | self.define = define_macros
|
@@ -477,4 +491,13 @@ def run(self):
|
477 | 491 | )
|
478 | 492 | _sdist.run(self)
|
479 | 493 |
|
480 |
| - return build_ext, sdist |
| 494 | + class bdist_wheel(_bdist_wheel): |
| 495 | + def get_tag(self): |
| 496 | + python, abi, plat = super().get_tag() |
| 497 | + |
| 498 | + if python.startswith("cp") and USE_PY_LIMITED_API: |
| 499 | + return f"cp{ABI3_TARGET_VERSION}", "abi3", plat |
| 500 | + |
| 501 | + return python, abi, plat |
| 502 | + |
| 503 | + return build_ext, sdist, bdist_wheel |
0 commit comments