3
3
import platform
4
4
import re
5
5
import shutil
6
+ import sys
6
7
from pathlib import Path
7
8
from typing import Any , Generator
8
9
15
16
16
17
# hardcoded SABI-related options. Requires that each Python interpreter
17
18
# (hermetic or not) participating is of the same major-minor version.
18
- version_tuple = tuple (int (i ) for i in platform .python_version_tuple ())
19
- py_limited_api = version_tuple >= (3 , 12 )
19
+ py_limited_api = sys .version_info >= (3 , 12 )
20
20
options = {"bdist_wheel" : {"py_limited_api" : "cp312" }} if py_limited_api else {}
21
21
22
22
@@ -43,10 +43,10 @@ def fmt_toolchain_args(matchobj):
43
43
return "python.toolchain(" + callargs + ")"
44
44
45
45
CIBW_LINUX = is_cibuildwheel () and IS_LINUX
46
+ module_bazel = Path ("MODULE.bazel" )
47
+ content : str = module_bazel .read_text ()
46
48
try :
47
49
if CIBW_LINUX :
48
- module_bazel = Path ("MODULE.bazel" )
49
- content : str = module_bazel .read_text ()
50
50
module_bazel .write_text (
51
51
re .sub (
52
52
r"python.toolchain\(([\w\"\s,.=]*)\)" ,
@@ -92,10 +92,16 @@ def copy_extensions_to_source(self):
92
92
def bazel_build (self , ext : BazelExtension ) -> None :
93
93
"""Runs the bazel build to create the package."""
94
94
temp_path = Path (self .build_temp )
95
- # omit the patch version to avoid build errors if the toolchain is not
96
- # yet registered in the current @rules_python version.
97
- # patch version differences should be fine.
98
- python_version = "." .join (platform .python_version_tuple ()[:2 ])
95
+ if py_limited_api :
96
+ # We only need to know the minimum ABI version,
97
+ # since it is stable across minor versions by definition.
98
+ # The value here is calculated as the minimum of a) the minimum
99
+ # Python version required, and b) the stable ABI version target.
100
+ # NB: This needs to be kept in sync with [project.requires-python]
101
+ # in pyproject.toml.
102
+ python_version = "3.12"
103
+ else :
104
+ python_version = "{0}.{1}" .format (* sys .version_info [:2 ])
99
105
100
106
bazel_argv = [
101
107
"bazel" ,
0 commit comments