Files
lancedb/ci/check_python_wheel.py
T
David Turner c9faa78cc6 feat(python): add free-threaded CPython 3.15 wheel support (#4961)
## Problem

The existing `cp310-abi3` wheel cannot be installed on free-threaded
CPython 3.15.

## Changes

- Keep `abi3-py310` in the default Cargo feature set and provide a
separate native free-threaded build profile with the same Python
distribution features.
- Build and validate `cp315-cp315t` release wheels for Linux x86-64 and
ARM64, macOS ARM64, and Windows x64; collect them with the existing
release artifacts.
- Add a Linux 3.15t CI job and tests for GIL state, concurrent
operations, and persistence. The existing regular-Python jobs retain the
full test suite.
- Validate compressed manylinux platform tags against the expanded
`WHEEL` metadata and use workspace-relative wheel paths in Python CI.

## Validation

- Built and validated Windows x64
`lancedb-0.42.0b10-cp310-abi3-win_amd64.whl` and
`lancedb-0.42.0b10-cp315-cp315t-win_amd64.whl` with Maturin 1.15.0 and
`--profile ci`.
- On the current PR commit `eecf193`, rebuilt the Windows x64 native
wheel, installed it on official CPython 3.15.0t, and ran `python -m
pytest python/python/tests/test_free_threaded.py -q`: 2 passed,
including GIL state and concurrent database operations.
- On the current PR commit, built a native Linux x86-64 `cp315-cp315t`
wheel with Maturin 1.15.0 and `--profile ci`, validated its wheel
metadata, installed it on CPython 3.15.2t, and ran `python -m pytest
python/tests/test_free_threaded.py -q`: 2 passed. This local Linux wheel
uses the native `linux_x86_64` platform tag, not a manylinux tag.
- Cargo feature regression check, Ruff, Python syntax, workflow YAML
parsing, and `git diff --check` passed.
- `python -m unittest discover -s ci/tests -p test_check_python_wheel.py
-v`: 4 passed on Windows and WSL Linux, including compressed manylinux
tags and mismatched metadata. The workflow's corrected wheel glob was
also checked from the `python` directory under WSL, and the two
free-threaded runtime tests passed from that directory on Windows.

The local ABI3 regression wheel was built before the rebase. The native
Windows and Linux free-threaded wheels and concurrency tests were built
from the current PR commit `eecf193`. The macOS and Linux manylinux
release artifacts still need validation in upstream CI. The full test
extra pulls optional dependencies requiring source builds on 3.15t, so
the new job installs the wheel and focused test dependencies; regular
jobs still run the full suite.

The complete CI-script suite passed locally on WSL Linux at commit
`eecf193`: `python3 -m unittest discover -s ci/tests -v` ran 39 tests
successfully with Rust 1.97, a user-space GCC toolchain, and Python's
`packaging` module. The upstream CI-script run is marked
`action_required`.

Closes #4641
2026-11-30 21:07:25 +08:00

111 lines
4.0 KiB
Python

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
"""Validate the ABI, platform, and contents of a built LanceDB wheel."""
from __future__ import annotations
import argparse
import re
import sys
from email.parser import BytesParser
from pathlib import Path
from zipfile import BadZipFile, ZipFile
PROFILES = {
"abi3": ("cp311", "abi3"),
"cp315t": ("cp315", "cp315t"),
}
def validate_wheel(wheel_path: Path, profile: str, platform_fragment: str) -> None:
expected_python, expected_abi = PROFILES[profile]
match = re.fullmatch(
r"lancedb-[^-]+-(?P<python>[^-]+)-(?P<abi>[^-]+)-"
r"(?P<platform>[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*)\.whl",
wheel_path.name,
)
if match is None:
raise ValueError(f"unexpected LanceDB wheel filename: {wheel_path.name}")
python_tag, abi_tag, platform_tag = match.groups()
if (python_tag, abi_tag) != (expected_python, expected_abi):
raise ValueError(
f"{wheel_path.name} has {python_tag}-{abi_tag}; expected "
f"{expected_python}-{expected_abi}"
)
if platform_fragment not in platform_tag:
raise ValueError(
f"{wheel_path.name} has platform {platform_tag!r}; expected "
f"it to include {platform_fragment!r}"
)
try:
with ZipFile(wheel_path) as archive:
names = archive.namelist()
wheel_metadata_paths = [
name for name in names if name.endswith(".dist-info/WHEEL")
]
metadata_paths = [
name for name in names if name.endswith(".dist-info/METADATA")
]
if len(wheel_metadata_paths) != 1 or len(metadata_paths) != 1:
raise ValueError("wheel must contain one WHEEL and one METADATA file")
wheel_metadata = BytesParser().parsebytes(
archive.read(wheel_metadata_paths[0])
)
distribution_metadata = BytesParser().parsebytes(
archive.read(metadata_paths[0])
)
tags = wheel_metadata.get_all("Tag", [])
expected_tags = {
f"{expected_python}-{expected_abi}-{platform}"
for platform in platform_tag.split(".")
}
if set(tags) != expected_tags or len(tags) != len(expected_tags):
raise ValueError(
f"WHEEL metadata has tags {tags!r}; expected {sorted(expected_tags)!r}"
)
distribution_name = (distribution_metadata.get("Name") or "").lower()
if distribution_name.replace("_", "-") != "lancedb":
raise ValueError(
f"wheel metadata names {distribution_name!r}, expected 'lancedb'"
)
if not (distribution_metadata.get("Requires-Python") or "").startswith(
">=3.11"
):
raise ValueError(
"wheel metadata does not preserve Requires-Python >=3.11"
)
if not any(
name.startswith("lancedb/_lancedb.")
and name.endswith((".pyd", ".so", ".dylib"))
for name in names
):
raise ValueError("wheel is missing the lancedb native extension")
except BadZipFile as exc:
raise ValueError(f"not a valid wheel archive: {wheel_path}") from exc
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("profile", choices=PROFILES)
parser.add_argument("--platform-fragment", required=True)
parser.add_argument("wheel", type=Path)
args = parser.parse_args()
try:
validate_wheel(args.wheel, args.profile, args.platform_fragment)
except (OSError, ValueError) as exc:
print(f"wheel validation failed: {exc}", file=sys.stderr)
return 1
print(f"validated {args.profile} wheel: {args.wheel.name}")
return 0
if __name__ == "__main__":
raise SystemExit(main())