Skip to content

Commit e8c7581

Browse files
committed
feat(pypi): add support for Python 3.12 and 3.13
Add build configuration for Python 3.12 and 3.13 to the PyPI package. Update the BUILD file with new compatibility tags and config settings, extend pypi_build.sh to accept the new Python versions, and add build steps in the GitHub Actions workflow. Fix whl_test.sh to rename wheels with unstamped variable names before pip installation. The py_wheel rule creates the base :whl target with literal stamp variables like _BUILD_EMBED_LABEL_ in the filename for Bazel caching purposes. Pip 25.x, which ships with Python 3.12+, strictly validates wheel filenames and rejects these as invalid version specifiers. Use sed to replace the unstamped variables with a valid placeholder version (0.0.0) for testing purposes. Python 3.14 support is not included because Python 3.14 has not yet been released (scheduled for October 2025). Fixes: #3186
1 parent 7ba714a commit e8c7581

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

.github/workflows/pypi_build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ jobs:
3838
- name: Build Wheel 3.11
3939
run: |
4040
python/tflite_micro/pypi_build.sh cp311
41+
- name: Build Wheel 3.12
42+
run: |
43+
python/tflite_micro/pypi_build.sh cp312
44+
- name: Build Wheel 3.13
45+
run: |
46+
python/tflite_micro/pypi_build.sh cp313
4147
- name: Check Directory Output
4248
run: |
4349
ls -l bazel-pypi-out

python/tflite_micro/BUILD

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ string_flag(
201201
values = [
202202
"cp310_cp310_manylinux_2_28_x86_64",
203203
"cp311_cp311_manylinux_2_28_x86_64",
204+
"cp312_cp312_manylinux_2_28_x86_64",
205+
"cp313_cp313_manylinux_2_28_x86_64",
204206
"local",
205207
],
206208
)
@@ -219,6 +221,20 @@ config_setting(
219221
},
220222
)
221223

224+
config_setting(
225+
name = "cp312_cp312_manylinux_2_28_x86_64",
226+
flag_values = {
227+
":compatibility_tag": "cp312_cp312_manylinux_2_28_x86_64",
228+
},
229+
)
230+
231+
config_setting(
232+
name = "cp313_cp313_manylinux_2_28_x86_64",
233+
flag_values = {
234+
":compatibility_tag": "cp313_cp313_manylinux_2_28_x86_64",
235+
},
236+
)
237+
222238
config_setting(
223239
name = "local",
224240
flag_values = {
@@ -235,18 +251,24 @@ py_wheel(
235251
abi = select({
236252
":cp310_cp310_manylinux_2_28_x86_64": "cp310",
237253
":cp311_cp311_manylinux_2_28_x86_64": "cp311",
254+
":cp312_cp312_manylinux_2_28_x86_64": "cp312",
255+
":cp313_cp313_manylinux_2_28_x86_64": "cp313",
238256
":local": "none",
239257
}),
240258
description_file = ":description_file",
241259
distribution = "tflite_micro",
242260
platform = select({
243261
":cp310_cp310_manylinux_2_28_x86_64": "manylinux_2_28_x86_64",
244262
":cp311_cp311_manylinux_2_28_x86_64": "manylinux_2_28_x86_64",
263+
":cp312_cp312_manylinux_2_28_x86_64": "manylinux_2_28_x86_64",
264+
":cp313_cp313_manylinux_2_28_x86_64": "manylinux_2_28_x86_64",
245265
":local": "any",
246266
}),
247267
python_tag = select({
248268
":cp310_cp310_manylinux_2_28_x86_64": "cp310",
249269
":cp311_cp311_manylinux_2_28_x86_64": "cp311",
270+
":cp312_cp312_manylinux_2_28_x86_64": "cp312",
271+
":cp313_cp313_manylinux_2_28_x86_64": "cp313",
250272
":local": "py3",
251273
}),
252274
requires = [

python/tflite_micro/pypi_build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ container. Uses bazel, but does not pollute the WORKSPACE's default cache.
2626
<python-tag> must be one of the supported interpreters:
2727
cp310
2828
cp311
29+
cp312
30+
cp313
2931
3032
<output-directory> defaults to $OUT_DIR_DEFAULT.
3133
"
3234

3335
case "$1" in
34-
cp310|cp311)
36+
cp310|cp311|cp312|cp313)
3537
PY_TAG=$1
3638
OUTDIR=$(realpath ${2:-$OUT_DIR_DEFAULT})
3739
mkdir -p $OUTDIR

python/tflite_micro/whl_test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ set -e
2121

2222
WHL="${1}"
2323

24+
# Rename wheel if it has unstamped variables in the filename. The py_wheel rule
25+
# creates two outputs: the base :whl target with literal stamp variables in the
26+
# filename (for Bazel caching), and :whl.dist with expanded variables. This test
27+
# uses :whl as its data dependency because :whl.dist isn't a proper Bazel target
28+
# that can be referenced in deps. Pip 25.x in Python 3.12+ strictly validates
29+
# wheel filenames and rejects literal stamp variables like _BUILD_EMBED_LABEL_.
30+
# Replace with a valid placeholder version for testing purposes.
31+
if echo "${WHL}" | grep -q '_BUILD_EMBED_LABEL_'; then
32+
RENAMED_WHL=$(echo "${WHL}" | sed 's/_BUILD_EMBED_LABEL_\.dev_STABLE_GIT_COMMIT_TIME_/0.0.0/')
33+
cp "${WHL}" "${RENAMED_WHL}"
34+
WHL="${RENAMED_WHL}"
35+
fi
36+
2437
# Create venv for this test.
2538
python3 -m venv pyenv
2639
. pyenv/bin/activate

0 commit comments

Comments
 (0)