Skip to content

Commit 3311045

Browse files
dmitriplotnikovcopybara-github
authored andcommitted
Add support for Python 3.12 and Python 3.13 wheels.
PiperOrigin-RevId: 866176356
1 parent 98dbfdb commit 3311045

5 files changed

Lines changed: 35 additions & 8 deletions

File tree

MODULE.bazel

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@ bazel_dep(name = "rules_proto", version = "7.1.0")
5353
# https://registry.bazel.build/modules/rules_python
5454
bazel_dep(name = "rules_python", version = "1.7.0")
5555

56-
python = use_extension("@pybind11_bazel//:python/python.bzl", "python")
57-
python.toolchain(python_version = "3.11")
56+
python_rules = use_extension("@rules_python//python/extensions:python.bzl", "python")
57+
python_rules.toolchain(
58+
is_default = True,
59+
python_version = "3.11",
60+
)

release/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@ To build the py_cel wheel locally for testing:
2525
- Update release version
2626
Edit `release/build_wheel.sh`: update `VERSION`
2727

28-
- Run `cibuildwheel`
28+
- Run `release/build_wheel.sh`
2929

3030
```
31-
cibuildwheel
31+
release/build_wheel.sh
32+
```
33+
34+
Optionally, provide the signature of a specific target configuration, e.g.
35+
36+
```
37+
release/build_wheel.sh --only "cp311-manylinux_x86_64"
3238
```
3339

3440
- Install the resulting wheel:
3541

3642
```
37-
pip uninstall py-cel
38-
pip install wheelhouse/py_cel-*.whl
43+
pip install --force-reinstall wheelhouse/py_cel-*.whl
3944
```
4045

4146
- Verify that the wheel is working correctly

release/build_wheel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cp "${SRC_DIR}"/release/* .
2727
sed -i "s/\$VERSION/${VERSION}/g" pyproject.toml
2828

2929
echo "Running cibuildwheel: ${CIBWHEEL_BIN}"
30-
"${CIBWHEEL_BIN}"
30+
"${CIBWHEEL_BIN}" "$@"
3131

3232
echo "Copying generated wheels to ${SRC_DIR}/wheelhouse"
3333
mkdir -p "${SRC_DIR}"/wheelhouse

release/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where = ["."]
2929
exclude = ["wheelhouse*", "conformance*", "custom_ext*"]
3030

3131
[tool.cibuildwheel]
32-
build = "cp311-*"
32+
build = "cp311-* cp312-* cp313-*"
3333
skip = "*musllinux*"
3434
before-all = "echo 'Installing bazelisk'; curl -LO https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64 && chmod +x bazelisk-linux-amd64 && mv bazelisk-linux-amd64 /usr/local/bin/bazel"
3535
test-command = "python {project}/py_cel_basic_test.py"

release/setup.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import shutil
1919
import subprocess
20+
import sys
2021
import setuptools
2122
import setuptools.command.build_ext
2223

@@ -40,6 +41,24 @@ def run(self):
4041
self.build_extension(ext)
4142

4243
def build_extension(self, ext):
44+
# cibuildwheel executes setup.py using the target Python version.
45+
# Thus, we can use the current Python version as the target version for
46+
# the bazel build.
47+
python_version = f'{sys.version_info.major}.{sys.version_info.minor}'
48+
print(f'Building for target Python version: {python_version}')
49+
50+
module_bazel_path = os.path.join(os.path.dirname(__file__), 'MODULE.bazel')
51+
if os.path.exists(module_bazel_path):
52+
sed_command = (
53+
f"sed -i 's/python_version\\s*=\\s*\".*\"/"
54+
f"python_version = \"{python_version}\"/' {module_bazel_path}"
55+
)
56+
subprocess.check_call(sed_command, shell=True)
57+
else:
58+
raise RuntimeError(
59+
f'MODULE.bazel not found at {module_bazel_path}'
60+
)
61+
4362
dest_path = self.get_ext_fullpath(ext.name)
4463
dest_dir = os.path.dirname(dest_path)
4564
os.makedirs(dest_dir, exist_ok=True)

0 commit comments

Comments
 (0)